Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 199
  • Last Modified:

Want to Determine if IP is Public or Not

Hi

I'm trying to develop a custom Internet server, with several services... In order to AUTO configure correctly
this server must know if the IP address got from DHCP or even entered from the user is Public or Not.

Parhaps you may think .. well.. test the first octets of the ip, and see if it is reserved but, remeber
not all ISP's give you a reserved IP for example a local ISP gives via dhcp a 11.41.0.0 IP address to it's customers.
but that address belongs to a PRIVATE network.

How can I determine if my IP is public or private?..

Thanks.
0
egarciat
Asked:
egarciat
  • 2
1 Solution
 
egarciatAuthor Commented:
of course the solution has to be "script-able" for example, a class mate toldme, enter www.whatismyip.com and see if the address is the same as your current address, but that is hard to implement as a script.
0
 
jmcgOwnerCommented:
A short script:

#! /bin/sh

ifconfig -a | perl -ne 'print $1, "\n" if /inet addr:([\d.]+)/' >/tmp/hostaddrs
lynx -dump http://www.whatismyip.com | fgrep -f /tmp/hostaddrs >/tmp/ipmatch
if [ -s /tmp/ipmatch ] ; then echo public ; else echo private; fi



of course, it could all be written in Perl, but then it might take 10 lines.
0
 
egarciatAuthor Commented:
very interesting let me tryit out..
0

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now