The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Operating Systems > OS X (Apple)
.
google unix.com



OS X (Apple) OS X is a line of Unix-based graphical operating systems developed, marketed, and sold by Apple.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Configuration File storing in a Hash Harikrishna Shell Programming and Scripting 1 05-29-2008 12:08 PM
Connecting To An External Network Using A logical (PACKAGE) IP Address cchilenga HP-UX 1 05-04-2008 05:16 PM
Ksh Storing Multiple Files and reading each line in each file. developncode UNIX for Dummies Questions & Answers 1 04-08-2008 05:44 PM
storing date into a file from a program bankpro High Level Programming 2 01-17-2006 05:28 AM
Connecting an external SCSI drive to a unix computer teruotor UNIX for Dummies Questions & Answers 3 08-09-2005 11:40 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 07-11-2008
Audacitor's Avatar
Audacitor Audacitor is offline
Registered User
  
 

Join Date: Jul 2008
Posts: 2
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 (permalink)  
Old 07-11-2008
DukeNuke2's Avatar
DukeNuke2 DukeNuke2 is offline Forum Staff  
Soulman
  
 

Join Date: Jul 2006
Location: Germany, Berlin
Posts: 2,993
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 (permalink)  
Old 07-11-2008
Audacitor's Avatar
Audacitor Audacitor is offline
Registered User
  
 

Join Date: Jul 2008
Posts: 2
I didn't know such a service existed. Thanks for the reference!
  #4 (permalink)  
Old 08-01-2008
Exolon Exolon is offline
Registered User
  
 

Join Date: Aug 2008
Posts: 2
Note that most routers nowadays should be able to tell you the WAN IP via UPNP.
  #5 (permalink)  
Old 08-02-2008
tlarkin tlarkin is offline
Registered User
  
 

Join Date: Mar 2008
Posts: 42
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 (permalink)  
Old 08-04-2008
verno verno is offline
Registered User
  
 

Join Date: Sep 2006
Posts: 14
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}'

  #7 (permalink)  
Old 08-13-2008
tlarkin tlarkin is offline
Registered User
  
 

Join Date: Mar 2008
Posts: 42
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?
Closed Thread

Bookmarks

Tags
email, external, learn unix, save, script

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 02:43 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0