PDA

View Full Version : Determine My own IP address


tmeehan
06-18-2003, 03:43 PM
I am trying to write a script that I can run as a cron job that will email my IP address to me at work. I realize there are shareware products out there that do the job but I need to be able to modify some things. Does any one have a script that will return my IP address.

Running 10.2.6

Thanks

yellow
06-18-2003, 04:03 PM
I don't know of a script offhand, but there is:

http://www.myipaddress.com/

mervTormel
06-18-2003, 04:14 PM
here's gip and dhtml:

#!/bin/sh

# file: gip -- get current public IP address and ftp it up

#set -xv

prog=`basename $0`
curl=/sw/bin/curl
cut=/sw/bin/cut
dhtml=~/bin/dhtml
egrep=/sw/bin/egrep
tee=/usr/bin/tee
ftp=/usr/bin/ftp
logger=/usr/bin/logger
curip=~/curip

checkIPurl='http://checkip.dyndns.org/'
grepStr="address|hostname"
ftpSite="ftp.mindspring.com"

set +o noclobber
${curl} -s ${checkIPurl} | ${dhtml} | \
${egrep} -i "${grepStr}" | ${tee} ${curip}

# ~/.netrc contains machine info for ftp site
${ftp} ${ftpSite} <<__end_ftp
put ${curip} curip
quit
__end_ftp

evHostIP=`${egrep} -i address ${curip} | ${cut} -d" " -f4`
export evHostIP

${logger} -i -p local3.info -t ${prog} "ip posted: ${evHostIP}"

# --------------- here's dhtml ------------

#!/usr/bin/perl -w

# file: dhtml - strip html tags

while (<>) {
$_ =~ s/<[^>]*>//g;
print;
}


it can be modified to email rather than post to an ftp space.

hayne
06-18-2003, 04:49 PM
There was a recent MacOSXHint on this very topic:
http://www.macosxhints.com/article.php?story=20030607094823255

Check out the comments to this hint as well - I contributed a script (similar to that of mervTormel's) that gets your IP addres via an external site.

AKcrab
06-18-2003, 05:05 PM
And there is this freeware:
Ipanema (http://www.ifthensoft.com/)

tmeehan
06-18-2003, 05:25 PM
I saw the recent hint:


http://www.macosxhints.com/article....030607094823255

But the actual script seems to be missing. The author calls


/Users/me/scripts/getip | mail -s "my IP at home" myemail@work.com


What's "getip" ? I am assuming that if I had the script "getip" I would have my answer.

Any clues?


:D

jdhorner
06-18-2003, 06:04 PM
that was his first method of automatically obtaining his IP address at home from work. basically, via cron, it auto-sends the IP every morning.

you should take more interest in the second half of that hint only... what IT allows you to do is email yourself at home, Mail.app will check that mail for a keyword you have set up in a rule in mail's prefs, and if that word is there, it will run the applescript that's in the second part of that hint.

*edit*
i didn't read that second part too thoroughly. it DOES call that script in BOTH parts of the hint. sorry for that.
*end edit*

griffman
06-18-2003, 06:07 PM
The URL for the "getip" script is in the hint, too:

"Credits: All props go to Jerry LeVan for his excellent perl script to fetch the ..." -- "perl script" is linked to the getip script.

-rob.

jdhorner
06-18-2003, 06:09 PM
ahh, edit, part 2. but later down, in the comments on that hint, you can find a few different takes on some scripts that you can use as your own "getip" script.

grrl_geek
06-18-2003, 08:27 PM
You can also get your current IP address this way:

ipconfig getifaddr en0

which will spit out something like

192.168.250.16

This won't help you if you're behind a router (because it won't be your *public* IP) but if you use PPPoE or dialup, it should.