What is my IP
Sometimes you may want to know which is your IP address, both your
- private ip address, that is the IP address of your network interface in your local network (LAN)
- public ip address, that is the IP address that identifies you when you're on internet (if you're in a local network, this IP address it's not related with your computer, but with the gateway of your local network towards the public internet).
The reasons why you may want to know these addresses can be the most different reasons:
- you're running a server on your computer, and you want to make it accessible from the other users of your local network (in this case you want to know your private address) or to other internet users (in this case you need your public address and you also have to set up some forwarding rules on your router)
- you want to test your network pinging your computer, but you don't know your IP address
- you want to update you entry in a dynamic DNS service, such has no-ip or dynDNS
- a script of your needs to know your computer address, for any reason
- and so on...
Scripts
A good way to deals with this problem is to use a script that automatically returns the information you need. What I posted here is a couple of scripts written for my Linux (Ubuntu) box.
readmyip
#!/bin/bash
wget -o /dev/null -O -
...http://www.whatismyip.com/automation/n09230945.asp
echo
Where of course the second line is not broken and dots have been added for clarity. You can download the script readmyip.
readmylocalip
#!/bin/bash
ifconfig 2>&1 | grep "inet addr:" | grep -v ":127." | awk '{print $2}' |
...tr -d addr:
Again, dots and line break have been added. You can download the script readmylocalip.
Usage
To use this scripts you just have to run them in your console. Of course you must have the permission to execute the script. This can be done with
chmod u+x readmy*
to give the permission to execute to the to the user who owns the file,
chmod g+x readmy*
to give this permission to other users who are members of the file’s group, and
chmod o+x readmy*
to allow execution to users that are in neither of the two preceding categories.
To run the scripts, you must be in the same directory in which they are, and call them with
./readmyip
and
./readmylocalip
(unless you have . in your PATH). The other, more efficient solution, is to move the scripts in a folder that already appears in your PATH variable, for example /usr/local/bin.
I hope you liked this page!
If you think it did help you, why don't you buy me a spritz ? ;-)

