Visit Our UNIX and Linux User Community


Getting the External IP Address of your Computer and Storing it in a File


 
Thread Tools Search this Thread
Operating Systems OS X (Apple) Getting the External IP Address of your Computer and Storing it in a File
# 1  
Old 07-11-2008
Getting the External IP Address of your Computer and Storing it in a File

My computer is one of three computer on our LAN. Our router is a Time Capsule. My computer is the only of of three computers that has been assigned a static IP address on the LAN, because it runs an Apache installation. I tinker around with web development from time to time, and I wanted to be able to demo my experiments to my friends without having to throw it on a flash drive.

My home computer doesn't have a domain name, of course. I access it with my IP address, which is dynamic, and changes whenever the cats dislodge the modem.

I'm trying to write a script that checks my external IP (there's only one, we don't have aliases or multiple routers or anything), and compares to the IP in a saved file. If it finds that the IP address it detected is different from the one in the file, it sends me an email and saves the new IP to the file, where it check it later on.

1. The script is called by launchd every 5 minutes.
2. The script checks my external IP.
3. It compares it to the IP in its save file.
4. If the IP is the same as the IP in the save file, the script quits.
5. If the IP is different, the script activates another program that sends me an email.
6. I recieve the email and can refer to IP address by looking at the message's header.

I'm new to UNIX, but not totally clueless. I can move around in my computer, move, copy, and delete files, ping servers, and other basic tasks. I usually learn a new command on my own, but in this case, ifconfig (which I think I need) is just way out of my league. Can anyone help?
# 2  
Old 07-11-2008
ifconfig won't be of any help in this case... your external ip is assigned to your router. you have to read the ip from your router (if this is possible).
why don't you use a ddns service like DynDNS: DNS Hosting, Email Delivery and Other Services ?
# 3  
Old 07-11-2008
I didn't know such a service existed. Thanks for the reference!
# 4  
Old 08-01-2008
Note that most routers nowadays should be able to tell you the WAN IP via UPNP.
# 5  
Old 08-03-2008
I wrote a script for someone to output the network information of a client machine to a text file. It doesn't display the external IP, but I am sure it can be tweaked to do so.

Code:
#!/bin/sh

/usr/sbin/networksetup -getinfo Ethernet | open -t -a

If running the command manually you need sudo, but DYNDNS.org is probably a better solution.
# 6  
Old 08-04-2008
You can also get your external ip address with curl.

Code:
curl -L -s --max-time 10 http://checkip.dyndns.org | egrep -o -m 1 '([[:digit:]]{1,3}\.){3}[[:digit:]]{1,3}'

This User Gave Thanks to verno For This Post:
# 7  
Old 08-13-2008
why not just download and install the dyndns client from DynDNS: DNS Hosting, Email Delivery and Other Services which will track your external IP for you?

Previous Thread | Next Thread
Test Your Knowledge in Computers #904
Difficulty: Medium
The benchmark used in the LINPACK Benchmark is to solve a dense system of nonlinear equations.
True or False?

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Finding specific string in file and storing in another file

Text in input file is like this <title> <band height="21" isSplitAllowed="true" > <staticText> <reportElement x="1" y="1" width="313" height="20" key="staticText-1"/> <box></box> <textElement> <font fontName="Arial" pdfFontName="Helvetica-Bold"... (4 Replies)
Discussion started by: aankita30
4 Replies

2. IP Networking

Ping domain indicates the external ip address and not the local ip

when i execute from local machine ping domainname i get the external ip address but i am on local dns and i expect the local ip address.. using nslookup : no problem so i cannot find why... thanks (2 Replies)
Discussion started by: activedms
2 Replies

3. Shell Programming and Scripting

External IP Address of Linux Server

Hi, I am trying to find the external IP address of a server "XXX". I logged into server "XXX" and executed nslookup XXX. output number is 123.23.23.45 Later, i have executed "curl http://whatismyip.org". This time i got a different number 611.34.63.22 Out of these two numbers, what number... (1 Reply)
Discussion started by: forums123456
1 Replies

4. OS X (Apple)

mailx to external email address

Hi, How can I use "mailx" command to send message to an email address like this? echo "This email body" | mailx -s "my subject" "email@hostname.com" There may be some setup required in sendmail or postfix?? OS = Snow Leopard 10.6 (4 Replies)
Discussion started by: FlyingSquirrel
4 Replies

5. UNIX for Dummies Questions & Answers

Storing PDF File

Hi, We have generated Some BO reports and These BO reports Needs to be stored in PDF File format in unix server. Will Unix Support to store PDF Files ? Many Thanks Sashu (1 Reply)
Discussion started by: Sashanth_S
1 Replies

6. UNIX for Dummies Questions & Answers

How to set server's ip address, router, network mask and set if it is an internal or external ip?

Hello, I need to write a program which sets server's ip address, router, network mask. Program also should set if it is an internal or external ip. Maybe someone can help me ? Any information from u is very useful :b: I stopped at .. :( #!/bin/sh A=`hostname -i` echo "server ip address is $A"... (4 Replies)
Discussion started by: zagaruika
4 Replies

7. IP Networking

How to find the IP address of a computer that I am connected to?

Hi all, One of my computers (an iMac) was recently stolen, but I have been able to connect to it over the internet through Apple's 'back to my mac' feature. In order for the police to find these people they need to know the IP address of the stolen computer. I suspect that I will have find the... (6 Replies)
Discussion started by: RJFoulston
6 Replies

8. IP Networking

Obtaining your external IP address using a Unix Utility

Hello, this is my first post on the Unix forums. This is something that's been bothering me for a while, is there any particular UNIX/Linux application that will allow you to see you external IP address? :confused: ( The address beyond your router ) Thank you in advance, I could not find a... (4 Replies)
Discussion started by: inquen
4 Replies

9. HP-UX

Connecting To An External Network Using A logical (PACKAGE) IP Address

Hie everyone, I am currently facing a problem whereby I can not connect to an external network from a package ip address on a HP-UX cluster. Below is the illustration: Primary Server IP Address : n.n.n.202 Secondary Server IP Address : n.n.n.212 Package IP Address : n.n.n.211 ... (1 Reply)
Discussion started by: cchilenga
1 Replies

10. UNIX for Dummies Questions & Answers

Connecting an external SCSI drive to a unix computer

I am interested in booting up my unix computer by connecting an external SCSI drive( intergraph) to it. The unix box is also an intergraph computer. Whenever I boot it, it gives me an error that says Drive not ready, Insert Boot Diskette in A. What am I doing wrong? Any input would be... (3 Replies)
Discussion started by: teruotor
3 Replies

Featured Tech Videos