et lille hack:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <windows.h>
#include <errno.h>
int main(int argc,char *argv[])
{
WSADATA WSAData;
int sd,status,len,ix,tmp;
char cmd[512],resp[51200],*p1,*p2;
struct sockaddr local,remote;
struct hostent *hostinfo;
WSAStartup(0x0101,&WSAData);
sd=socket(AF_INET,SOCK_STREAM,0);
if(sd<0) {
printf("Error creating socket: %s\n",strerror(errno));
goto fin;
}
local.sa_family=AF_INET;
memset(local.sa_data,0,sizeof(local.sa_data));
status=bind(sd,&local,sizeof(local));
if(status<0) {
printf("Error binding socket: %s\n",strerror(errno));
goto fin;
}
hostinfo=gethostbyname("
www.myip.dk");
if(!hostinfo) {
printf("Error looking up host: %s\n","
www.myip.dk");
goto fin;
}
remote.sa_family=hostinfo->h_addrtype;
memcpy(remote.sa_data+2,hostinfo->h_addr_list[0],hostinfo->h_length);
*((short *)remote.sa_data)=80;
tmp=remote.sa_data[0];
remote.sa_data[0]=remote.sa_data[1];
remote.sa_data[1]=tmp;
status=connect(sd,&remote,sizeof(remote));
if(status!=0) {
printf("Error connecting to host: %s port: %d\n","
www.myip.dk",80);
goto fin;
}
sprintf(cmd,"GET %s HTTP/1.1\r\nHost: %s\r\nwww.myip.dk\r\n\r\n","/","
www.myip.dk");
status=send(sd,cmd,strlen(cmd),0);
if(status<0) {
printf("Error sending GET request\n");
goto fin;
}
ix=0;
while ((len=recv(sd,resp+ix,sizeof(resp)-ix-1,0))>0) {
ix = ix + len;
}
resp[ix]='\0';
p1=strstr(resp,"<title>Your IP: ");
p1+=strlen("<title>Your IP: ");
p2=strstr(p1,"</title>");
*p2='\0';
printf("IP=%s\n",p1);
fin:
closesocket(sd);
WSACleanup();
return 0;
}