Router Information

This is a discussion on Router Information within the Networking/Device Communication forums, part of the General Programming Boards category; Hello everyone, I have made this function to determine if the user has a router or not, is this a ...

  1. #1
    Registered User
    Join Date
    May 2007
    Posts
    2

    Router Information

    Hello everyone,

    I have made this function to determine if the user has a router or not, is this a good method for retrieving IP, any feedback is appreciated.

    Code:
    	BYTE r = RouterCheck();
    	if(r == 10 || r == 192) {
           //Found Router IP, Retrieve IP via whatismyip.com or some other online website for retrieving IP.
    	}
    Code:
    BYTE RouterCheck() {
    	WORD wVersionRequested;
    	WSADATA wsaData;
    	char name[255];
    	char ip[16], fip[4];
    	PHOSTENT hostinfo;
    
    	wVersionRequested = MAKEWORD( 2, 0 );
    	
    	if ( WSAStartup( wVersionRequested, &wsaData ) == 0 ) {
    		if( gethostname ( name, sizeof(name)) == 0) {
    			if((hostinfo = gethostbyname(name)) != NULL) {
    				strcpy(ip, inet_ntoa (*(struct in_addr *)*hostinfo->h_addr_list));
    			}
    		}
    		else {
    			WSACleanup();
    			return NULL;
    		}
    		WSACleanup();
    	}
    	else return NULL;
    
    	char *p;
    	p = strchr(ip, '.');
    	if(p == NULL) return NULL; //p-ip
    	strncpy(fip, ip, p-ip);
    
    	return (BYTE)atoi(fip);
    }

  2. #2
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,484
    The strncpy function copies the initial count characters of strSource to strDest and returns strDest. If count is less than or equal to the length of strSource, a null character is not appended automatically to the copied string.
    and you pass its result as is to atoi. You have no crash yet? Lucky you...
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

  3. #3
    Malum in se abachler's Avatar
    Join Date
    Apr 2007
    Posts
    3,189
    and you assume they dont have a static IP....
    Until you can build a working general purpose reprogrammable computer out of basic components from radio shack, you are not fit to call yourself a programmer in my presence. This is cwhizard, signing off.

  4. #4
    int x = *((int *) NULL); Cactus_Hugger's Avatar
    Join Date
    Jul 2003
    Location
    Banks of the River Styx
    Posts
    902
    To the original poster: Not quite. A valid internet IP is 192.88.0.1 - you must check for both 192 and the 168. However, just checking for a leading 10 is OK. ( The ranges are 10.* and 192.168.* ) There are actually two other ranges of private IPs, which you should probably be checking for. See the wikipedia article: IPv4 - Private Networks. Also, be aware that sites such as "what's my ip" may not like automated hits. (And future changes in page layout could break your application.) Some of these sites, however, do provide an interface for bots/programs, but limit the number of hits per day. You could also run a simple server yourself to report back IPs.
    Quote Originally Posted by whatismyipaddress.com
    We are currently processing over 500,000 client requests per day and are not interested in serving up the full page to those requests. Something about an extra 30+ GB of bandwidth a month is not appealing to us. If you would like to utilize our site's service for automated lookups we are willing to work with you.
    Quote Originally Posted by abachler
    and you assume they dont have a static IP....
    How/where does he make this assumption? If an ISP assigns static IPs, they shouldn't be in the private address ranges he's checking for.
    long time; /* know C? */
    Unprecedented performance: Nothing ever ran this slow before.
    Any sufficiently advanced bug is indistinguishable from a feature.
    Real Programmers confuse Halloween and Christmas, because dec 25 == oct 31.
    The best way to accelerate an IBM is at 9.8 m/s/s.
    recursion (re - cur' - zhun) n. 1. (see recursion)

  5. #5
    Malum in se abachler's Avatar
    Join Date
    Apr 2007
    Posts
    3,189
    he is checking if they HAVE a router by assuming that anyone with an IP in the private address ranges has a router, btu his unstated counter assumption is that anyone that doesnt have a private IP doesnt have a router, which is not necessarily the case.

    Just because my IP isnt in 192.168.x.x or one of the other private networks, doesnt mean I dont have a router/switch/bridge.

    and just because my IP IS in one of the private networks doesnt mean I DO have a router, since it could be a truly private network.
    Last edited by abachler; 05-31-2007 at 02:52 PM.
    Until you can build a working general purpose reprogrammable computer out of basic components from radio shack, you are not fit to call yourself a programmer in my presence. This is cwhizard, signing off.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 5
    Last Post: 06-01-2009, 07:54 PM
  2. fsckin router
    By RoD in forum Tech Board
    Replies: 8
    Last Post: 01-23-2005, 11:42 AM
  3. Damn router
    By RoD in forum Tech Board
    Replies: 7
    Last Post: 05-04-2004, 02:27 PM
  4. Going out of scope
    By nickname_changed in forum C++ Programming
    Replies: 9
    Last Post: 10-12-2003, 06:27 PM
  5. Special Allegro Information
    By TechWins in forum Game Programming
    Replies: 12
    Last Post: 08-20-2002, 11:35 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21