SHARE
TWEET

Untitled

a guest Feb 22nd, 2019 73 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <WinSock2.h>
  2. #pragma comment(lib,"WS2_32")
  3. #include <Windows.h>
  4. #include <stdio.h>
  5.  
  6. struct GEOIP
  7. {
  8.     char ipaddress[16];
  9.     char countrycode[4];
  10.     char countryname[32];
  11.     char regioncode[4];
  12.     char regionname[32];
  13. };
  14.  
  15. char *trimstr(char *str)
  16. {
  17.     char *temp = str+1;
  18.     temp[strlen(temp)-1] = 0;
  19.     return temp;
  20. }
  21.  
  22. char *GeoIP()
  23. {
  24.     SOCKET hSocket = socket(AF_INET,SOCK_STREAM,IPPROTO_TCP);
  25.     sockaddr_in sockinfo;
  26.     sockinfo.sin_family = AF_INET;
  27.     sockinfo.sin_port = htons(80);
  28.     sockinfo.sin_addr.S_un.S_addr = *(unsigned long*)(gethostbyname("freegeoip.net")->h_addr_list[0]);
  29.     connect(hSocket,(sockaddr*)&sockinfo,sizeof(sockinfo));
  30.     char request[] = "GET /csv/ HTTP/1.1 \r\nHost: freegeoip.net\r\nUser-Agent: sbot\r\nConnection: close\r\n\r\n";
  31.     send(hSocket,request,sizeof(request)-1,0);
  32.     char tempbuf[1024];
  33.     recv(hSocket,tempbuf,1024,0);
  34.     char *content = strstr(tempbuf,"\r\n\r\n")+4;
  35.     closesocket(hSocket);
  36.     char *junk;
  37.     char msg[128];
  38.     char *ip = trimstr(strtok(content,","));
  39.     junk = strtok(NULL,",");
  40.     char *country = trimstr(strtok (NULL,","));
  41.     junk = strtok(NULL,",");
  42.     char *region = trimstr(strtok (NULL,","));
  43.     char *city = trimstr(strtok(NULL,","));
  44.     sprintf(msg,"%s - %s, %s, %s",ip,country,region,city);
  45.     return msg;
  46. }
  47.  
  48. int main()
  49. {
  50.     //printf("Downloading GEOIP information...\n\n");
  51.     WSADATA wsaData;
  52.     WSAStartup(MAKEWORD(2,2),&wsaData);
  53.     printf(GeoIP());
  54.     getchar();
  55.     WSACleanup();
  56.     return 0;
  57. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top