Want to Determine if IP is Public or Not

Posted on 2005-03-30
Medium Priority
Last Modified: 2010-03-17

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

Question by:egarciat
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2

Author Comment

ID: 13669335
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.
LVL 20

Accepted Solution

jmcg earned 500 total points
ID: 13669567
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.

Author Comment

ID: 13723515
very interesting let me tryit out..

Featured Post

Linux Academy Android App Now Supports Chromecast

We have some fantastic news for our Android fans. We’re so excited to announce that the Linux Academy Android app is now available with Chromecast support. That’s right – simply download the latest update of the Linux Academy App and start casting your favorite course videos!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I have seen several blogs and forum entries elsewhere state that because NTFS volumes do not support linux ownership or permissions, they cannot be used for anonymous ftp upload through the vsftpd program.   IT can be done and here's how to get i…
Note: for this to work properly you need to use a Cross-Over network cable. 1. Connect both servers S1 and S2 on the second network slots respectively. Note that you can use the 1st slots but usually these would be occupied by the Service Provide…
If you're a developer or IT admin, you’re probably tasked with managing multiple websites, servers, applications, and levels of security on a daily basis. While this can be extremely time consuming, it can also be frustrating when systems aren't wor…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…

801 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question