any ideas how to check if an IP is private? is there maybe a function for this that i don't know about?
thanks
any ideas how to check if an IP is private? is there maybe a function for this that i don't know about?
thanks
Private IPs have a specified range. Check out this. It looked like it outlined things nicely.
Those are standard. Thus they will always be private. So just check what IP range the user is falling into. I gather you need to know if they are private in order to use other means to determine their WAN. Or are you trying to automate port settings?
well theres a server with a real IP and theres a client from that server's LAN that connects to the real IP of that server, if you get the IP of the client it will be a private one.. im trying to find out if it is private so i will know its real IP is the same as the server's.. im not sure you understood lol
looks like i gotta make my own function for this using a CString..
thanks
Yeah you are pretty much on the right track, although why use a CString? An IP is 4bytes. You can can directly compare an IP to another IP using an IP mask. That is far easier to implement than doing string comparisons.
Example:
Code:unsigned int ip_mask = MAKE_IP(192, 0, 0, 0); if((ip & ip_mask) == ip_mask) private_ip = true;
Last edited by master5001; 10-11-2008 at 03:34 PM.
Ah yes, thank you tabstop. I don't know what I would do without you.
actually this was a bad idea.. i actually want a function to check if an IP can not be used over the internet and this is impossible to know.. as there are some other special IP's which could or could not be allowed to be used over the internet..
http://www.iana.org/abuse/faq.html
so im going to give up on this function.. thanks a lot for the help anyway
There are RFC's for reserved IP address ranges, existenZ. I was not yanking your leg. I am not saying it is *impossible* for these IPs to exist on the world-wide-web. I am just saying that they are not supposed to be. Do what you wish, friend. I think you are safe designing a function that conforms to the standard.
oh don't get me wrong, i wasn't saying that your idea was a bad idea.. just my idea of solving a problem of mine was bad from the beginning.. i just didn't think enough of what i was doing actually..
sorry i wasn't clear..
I think your idea is possible, is all I am saying. Lets use some HTTP RFCs for the sake of argument. A server is supposed to give a browser the content type and length of the file that is going to be transmitted. That doesn't mean it is impossible for a rogue server out there to diabolically not conform.
The same is true for IP addresses. Though IP addresses really are more controlled than web-servers. You will never find 127.0.0.1 as a web address ever. It just cannot happen.
There are two ways to check a particular IP.
Theoretical: If the IP falls into one of the reserved ranges, it is private.
Empirical: If the IP is addressable from the public internet, it is public, else it is private.
The empirical test can't really be performed, so you're stuck with theory.
Note that the private IP ranges are a matter of standard and convention only. If you placed a device on the public network with an address of, say, 192.168.10.1, then it could potentially work but only if all the routers agreed to play ball. And most of them will not.
Code://try //{ if (a) do { f( b); } while(1); else do { f(!b); } while(1); //}
brewbuck, that was a very eloquent way to put the point I was trying to explain. The exceptions to the rule are few and far between and could be best addressed in the "Known issues" section of your version information.