Go Back   The macosxhints Forums > OS X Help Requests > Networking



Reply
 
Thread Tools Rate Thread Display Modes
Old 06-18-2003, 04:43 PM   #1
tmeehan
Triple-A Player
 
Join Date: Jun 2003
Posts: 63
10.1 Determine My own IP address

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
tmeehan is offline   Reply With Quote
Old 06-18-2003, 05:03 PM   #2
yellow
Moderator
 
Join Date: Jan 2002
Posts: 10,652
I don't know of a script offhand, but there is:

http://www.myipaddress.com/
__________________
Chameleon's Consignment Loft]
yellow is offline   Reply With Quote
Old 06-18-2003, 05:14 PM   #3
mervTormel
League Commissioner
 
Join Date: Jan 2002
Posts: 5,536
here's gip and dhtml:
Code:
#!/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.
mervTormel is offline   Reply With Quote
Old 06-18-2003, 05:49 PM   #4
hayne
Moderator
 
Join Date: Jan 2002
Location: Montreal
Posts: 29,279
macosxhint

There was a recent MacOSXHint on this very topic:
http://www.macosxhints.com/article.p...30607094823255

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.
hayne is offline   Reply With Quote
Old 06-18-2003, 06:05 PM   #5
AKcrab
MVP
 
Join Date: Jan 2002
Location: Wasilla, AK
Posts: 1,043
And there is this freeware:
Ipanema
AKcrab is offline   Reply With Quote
Old 06-18-2003, 06:25 PM   #6
tmeehan
Triple-A Player
 
Join Date: Jun 2003
Posts: 63
10.1 Getting IP Address

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?


tmeehan is offline   Reply With Quote
Old 06-18-2003, 07:04 PM   #7
jdhorner
Major Leaguer
 
Join Date: Nov 2002
Location: Montréal, QC, Canada
Posts: 329
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*

Last edited by jdhorner; 06-18-2003 at 07:06 PM.
jdhorner is offline   Reply With Quote
Old 06-18-2003, 07:07 PM   #8
griffman
Site Admin
 
Join Date: Dec 2001
Location: Portland, OR
Posts: 1,441
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.
griffman is offline   Reply With Quote
Old 06-18-2003, 07:09 PM   #9
jdhorner
Major Leaguer
 
Join Date: Nov 2002
Location: Montréal, QC, Canada
Posts: 329
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.
jdhorner is offline   Reply With Quote
Old 06-18-2003, 09:27 PM   #10
grrl_geek
Major Leaguer
 
Join Date: Feb 2003
Location: Berkeley, CA
Posts: 270
You can also get your current IP address this way:

Code:
ipconfig getifaddr en0
which will spit out something like

Code:
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.
grrl_geek is offline   Reply With Quote
Reply

Thread Tools
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 On
HTML code is Off

Forum Jump


All times are GMT -5. The time now is 05:15 AM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Site design © Mac Publishing LLC; individuals retain copyright of their postings
but consent to the possible use of their material in other areas of Mac Publishing LLC.