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

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

Want to Determine if IP is Public or Not


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 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?..

  • 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.
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.
egarciatAuthor Commented:
very interesting let me tryit out..

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