hi guys it is good idea to have a good & complete tutorial about ip & ip finding , valid or invalid ip ,internal & external ip , ip spoofing , subnet ,subnet mask & other related material in this field . ===================================== thanks in advance -------------------------------------------------------------------
abuse
Sep 27 2003, 12:05 AM
Simple routine to get a host's routable IP:
CODE
ULONG GetHostIP(void) { char FAR name[255]; gethostname(name, 255); struct hostent FAR * pHostent; pHostent = gethostbyname(name); if(!pHostent) return 0; //all IP addresses: int i; for(i=0;i < 100;i++) { if(!pHostent->h_addr_list[i]) break; in_addr tmp; tmp.S_un.S_addr = *(DWORD *) pHostent->h_addr_list[i]; sprintf(name,"%.2u: %s\n",i,inet_ntoa(tmp)); printf(name); } //Only one ip ? if(pHostent->h_addr_list[1] == 0) { return *(ULONG *) pHostent->h_addr_list[0]; } //Choose a non-internal IP UCHAR *ip; for(i=0;pHostent->h_addr_list[i]!=0;i++) { ip = (UCHAR*) pHostent->h_addr_list[i]; if(ip[0]==10) continue; if((ip[0]==172)&&( (ip[1]>=16)&&(ip[1]<=31) )) continue; if((ip[0]==192)&&(ip[1]==168)) continue; return *(ULONG *) pHostent->h_addr_list[i]; } return 0; }
Spoofing aint really hard, but be aware that this only works for UDP/ICMP as connection oriented protocols like TCP obviously need valid receivers and senders. On win this goes a little like this:
CODE
char data[] = "test"; int datalen = (int) strlen(data);