How to decide if internet or LAN ip?
I want to know my ip address for internet. I use gethostname() and then gethostbyname() with the result of the first. Now I get a list of all my IPs, but how do I know which one is the internet ip? The only way I can imagine is to check which network class the ip is. Is this a good idea, or is there a better way?
Re: How to decide if internet or LAN ip?
but how can you classify them ?
Re: How to decide if internet or LAN ip?
One idea, you know your IP and sub-net mask. Compare the IP's net id with yours ( using mask and IP ). If it is the same you know that it belongs to your subnet. Otherwise it belongs to the outer subnet/network.
Re: How to decide if internet or LAN ip?
Quote:
Originally Posted by Mathew Joy
One idea, you know your IP and sub-net mask. Compare the IP's net id with yours ( using mask and IP ). If it is the same you know that it belongs to your subnet. Otherwise it belongs to the outer subnet/network.
Well, I know my IP but I can't hard code it because it is a multi-user program. And that is also the problem with classification of the IPs:
Quote:
Originally Posted by grabbler
but how can you classify them
Normally home networks have IPs starting with at least 192. That's because of the class A network ip address range selected by ICANN. That's how I do it now. The problem is: users might not always stick to the ICANN, when selecting their LAN ip.
Re: How to decide if internet or LAN ip?
Quote:
Originally Posted by philkr
Well, I know my IP but I can't hard code it because it is a multi-user program. And that is also the problem with classification of the IPs:
Hard coding? Why do you need to hard code your IP?
See How to get the local IP address(es)? for more details..
Quote:
Originally Posted by philkr
Normally home networks have IPs starting with at least 192. That's because of the class A network ip address range selected by ICANN. That's how I do it now. The problem is: users might not always stick to the ICANN, when selecting their LAN ip.
Well, 192 IP range belongs to class C.
Re: How to decide if internet or LAN ip?
Quote:
Originally Posted by Mathew Joy
Hard coding? Why do you need to hard code your IP?
Sorry, it seems I misunderstood the first part of your post.
Quote:
Originally Posted by Mathew Joy
Well, 192 IP range belongs to class C.
Yes, that's what I meant. I got mixed up. However, thanks for the link, I will rate it.
Re: How to decide if internet or LAN ip?
Quote:
Originally Posted by philkr
However, thanks for the link, I will rate it.
You don't have to mention it...rating is up to the individual to. Rating or no rating...we are here to help. :)
Re: How to decide if internet or LAN ip?
you can get your IP Address details, through this site http://www.ip-details.com/ip-search/
It has the best result about internet service provider,location, country and and also provides the IP details at free cost itself.......