 |
 |
Q: How get current IP addres in shell?
|
 |
|
 |
|
Dedicated MacNNer
Join Date: Feb 2003
Status:
Offline
|
|
Hi,
I hate to keep looking up my current dynamic IP address in System preferences, There has to be a clean shell way. The best I can do so far is:
ifconfig -u | grep netmask
But that gives me other info. Anything that just provides the currnt IP address?
Thanks.
|
|
|
| |
|
|
|
 |
|
 |
|
Senior User
Join Date: Jan 2001
Location: Mahwah, NJ USA
Status:
Offline
|
|
Originally posted by jgift:
Hi,
I hate to keep looking up my current dynamic IP address in System preferences, There has to be a clean shell way. The best I can do so far is:
ifconfig -u | grep netmask
But that gives me other info. Anything that just provides the currnt IP address?
Thanks.
Try:
ipconfig getifaddr en0
that should return the IP address of interface en0 and nothing else.
|
|
-DU-...etc...
|
| |
|
|
|
 |
|
 |
|
Dedicated MacNNer
Join Date: Feb 2003
Status:
Offline
|
|
Thanks but I get a kernel error... I used ifconfig and some grep and awk statements to finally get it.
Would have been cleaner your way 
|
|
|
| |
|
|
|
 |
|
 |
|
Senior User
Join Date: Jul 2000
Status:
Offline
|
|
Originally posted by jgift:
Thanks but I get a kernel error... I used ifconfig and some grep and awk statements to finally get it.
Would have been cleaner your way
Try running "ipconfig getifaddr en1". I got an error as well, but I'm not on eno (Ethernet) as I'm using my built-in AirPort card (en1).
|
|
|
| |
|
|
|
 |
|
 |
|
Dedicated MacNNer
Join Date: Jul 2001
Location: NC
Status:
Offline
|
|
Originally posted by jgift:
Thanks but I get a kernel error... I used ifconfig and some grep and awk statements to finally get it.
awk can do it all by it's lonesome. Try the following:
ifconfig en0 | awk '/inet /{print $2}'
|
|
Gary
A computer scientist is someone who, when told to "Go to Hell", sees the
"go to", rather than the destination, as harmful.
|
| |
|
|
|
 |
|
 |
|
Dedicated MacNNer
Join Date: Feb 2003
Status:
Offline
|
|
Thanks for the help...
1. Tried ipconfig getifaddr en1 but got the same:
get if addr en1 failed, (os/kern) failure
Tried it as PPP0 since I have an ethernet ADSL modem here. No go either.
2. I had an awk statement that did it great:
ifconfig -a | grep "inet" | grep "netmask" | grep -v "127.0.0.1" | awk {'print $2'}
But the new one posted does it in half the space... very clever. Thanks Gary!
I just replaced:
ifconfig en0 | awk '/inet /{print $2}'
with
ifconfig ppp0 | awk '/inet /{print $2}'
(Last edited by jgift; Jul 19, 2003 at 08:42 AM.
)
|
|
|
| |
|
|
|
 |
|
 |
|
Mac Enthusiast
Join Date: Sep 2000
Location: France
Status:
Offline
|
|
What if you're behind a router ? Does anyboy konw how I can get my public IP (i.e. my Basestation's IP) from the Terminal ?
|
|
|
| |
|
|
|
 |
|
 |
|
Senior User
Join Date: Jan 2001
Location: california
Status:
Offline
|
|
Originally posted by Axel:
What if you're behind a router ? Does anyboy konw how I can get my public IP (i.e. my Basestation's IP) from the Terminal ?
you'll have to get it in the airport admin utility, i'm pretty sure. if you always leave it on, then that ip shouldn't change, in which case you can write down the ip or put it in a text file :c)
|
|
|
| |
|
|
|
 |
|
 |
|
Dedicated MacNNer
Join Date: Jul 2001
Location: NC
Status:
Offline
|
|
Originally posted by Axel:
What if you're behind a router ? Does anyboy konw how I can get my public IP (i.e. my Basestation's IP) from the Terminal ?
Yes, simply execute the following:
curl -s http://simple.showmyip.com
|
|
Gary
A computer scientist is someone who, when told to "Go to Hell", sees the
"go to", rather than the destination, as harmful.
|
| |
|
|
|
 |
|
 |
|
Senior User
Join Date: Oct 2000
Location: Midwest
Status:
Offline
|
|
Substitute en1 for en0 if you are connected via an airport card.
Code:
ifconfig en0|awk '/inet /{print $2}'
HTH
Craig
|
|
|
| |
|
|
|
 |
|
 |
|
Dedicated MacNNer
Join Date: Feb 2003
Status:
Offline
|
|
Time to kill and playing around. This works also for me ...
tail /tmp/ppp.log | awk '/local /{print $10}'
|
|
|
| |
|
|
|
 |
|
 |
|
Dedicated MacNNer
Join Date: Dec 2002
Location: someplace
Status:
Offline
|
|
Originally posted by Gary Kerbaugh:
Yes, simply execute the following:
curl -s http://simple.showmyip.com
Gary, have you had any problems lately with the showmyip.com domain? I have had trouble getting their subdomains to resolve properly lately. Perhaps it is just my DNS servers at fault. I'll do some experiments with some remote shell accounts and see if it's a local issue or net-wide. In the meantime, I have a broken script or two to deal with!
|
|
|
| |
|
|
|
 |
|
 |
|
Dedicated MacNNer
Join Date: Dec 2002
Location: someplace
Status:
Offline
|
|
Well, I've tried shell accounts in California, Georgia, and Massachusetts with the same results:
Code:
bash-2.05$ host -v simple.showmyip.com
Trying "simple.showmyip.com"
Host simple.showmyip.com not found: 3(NXDOMAIN)
Received 37 bytes from 64.224.20.156#53 in 115 ms
bash-2.05$ lynx -dump http://simple.showmyip.com
Looking up simple.showmyip.com
simple.showmyip.com
Unable to locate remote host simple.showmyip.com.
Alert!: Unable to connect to remote host.
lynx: Can't access startfile http://simple.showmyip.com/
bash-2.05$ curl -s http://simple.showmyip.com
bash-2.05$
Time to fall back to the older, slightly less efficient:
curl -s http://checkip.dyndns.org/ | awk '/Current IP Address:/ {print $4}'
|
|
|
| |
|
|
|
 |
|
 |
|
Mac Enthusiast
Join Date: Jun 2000
Location: New Jersey, USA
Status:
Offline
|
|
Is there some reason why I wouldn't have ipconfig on my machine? For that matter, I can't find ping either, except as part of Network Utility.app. Aren't these standard, or is there some package I need to install?
|
|
|
| |
|
|
|
 |
|
 |
|
Dedicated MacNNer
Join Date: Feb 2003
Status:
Offline
|
|
They should be standard. have you the BSD package installed?
|
|
|
| |
|
|
|
 |
|
 |
|
Mac Enthusiast
Join Date: Jun 2000
Location: New Jersey, USA
Status:
Offline
|
|
I'm not sure what you mean by "BSD Package". I've got 10.2.6 with dev tools installed.
Where are ipconfig and ping normally found?
|
|
|
| |
|
|
|
 |
|
 |
|
Dedicated MacNNer
Join Date: Jul 2001
Location: NC
Status:
Offline
|
|
Originally posted by gatorparrots:
Gary, have you had any problems lately with the showmyip.com domain? I have had trouble getting their subdomains to resolve properly lately. Perhaps it is just my DNS servers at fault. I'll do some experiments with some remote shell accounts and see if it's a local issue or net-wide. In the meantime, I have a broken script or two to deal with!
Hi gatorparrots,
Forgive the late reply; I check this list less frequently than my normal haunt. (and you know where that is) I've had no problems but I don't use it regularly. However, I have used it several times since this post and it's worked fine. Wasn't it you that told me about it? I remember that there was another site mentioned in the same thread at Apple. It required an awk filter as it included HTML but it worked. Unfortunately I don't remember what it was and the thread appears to have been archived.
|
|
Gary
A computer scientist is someone who, when told to "Go to Hell", sees the
"go to", rather than the destination, as harmful.
|
| |
|
|
|
 |
|
 |
|
Dedicated MacNNer
Join Date: Jul 2001
Location: NC
Status:
Offline
|
|
Originally posted by neilw:
Is there some reason why I wouldn't have ipconfig on my machine? For that matter, I can't find ping either, except as part of Network Utility.app. Aren't these standard, or is there some package I need to install?
ipconfig is installed by the Essentials.pkg installer package in /usr/sbin/ipconfig and ping is installed by the BaseSystem.pkg installer package in /sbin/ping. Therefore the discussion about the BSD subsystem is moot. If you look in the MacOS X installer disk 1 you can find these installer packages and use Pacifist to pull out the files you need.
|
|
Gary
A computer scientist is someone who, when told to "Go to Hell", sees the
"go to", rather than the destination, as harmful.
|
| |
|
|
|
 |
|
 |
|
Dedicated MacNNer
Join Date: Dec 2002
Location: someplace
Status:
Offline
|
|
Originally posted by Gary Kerbaugh:
Hi gatorparrots,
Forgive the late reply; I check this list less frequently than my normal haunt. (and you know where that is) I've had no problems but I don't use it regularly. However, I have used it several times since this post and it's worked fine. Wasn't it you that told me about it? I remember that there was another site mentioned in the same thread at Apple. It required an awk filter as it included HTML but it worked. Unfortunately I don't remember what it was and the thread appears to have been archived.
Yes, it was I who made mention of http://simple.showmyip.com on your other haunt. Oddly enough, that subdomain now works here. It hadn't resolved all weekend, but now it appears that their DNS or server issues are resolved.
While slightly less efficient, I've never had a problem with this code in a script:
curl -s http://checkip.dyndns.org/ | awk '/Current IP Address:/ {print $4}'
Although, I did just find a perl script that is seemingly more efficient than either of the other two commands. Instead of requesting a remote site's IP discovery page and returning the results, this one gets the external IP address from a LAN-based router:
Code:
#!/usr/bin/perl
#
# fetch the current ip address from a Linksys BEFSR... series router
# replace ":admin" with a custom password, if appropriate
# Jerry LeVan (jerry.levan@eku.edu)
# Mac OS X 10.1.4
# May 12,2002
#
my ($pattern,$thePage,$theAddress,$wan,$ip,$theip);
#define the pattern we are looking for...
$wan = '^.*<!--WAN head-->.*';
$ip = 'IP Address:</td><td><font face=verdana size=2>';
$theip = '(\d+\.\d+\.\d+\.\d+)</td';
$pattern = $wan.$ip.$theip;
# Fetch the page
$thePage = `curl -s -u :admin http://192.168.1.1/Status.htm` ;
# Look for the current IP embedded in the Status Page
if ($thePage =~ m|$pattern|)
{
$theAddress = $1;
print $theAddress,"\n";
# here you could mail the address ...
}
else
{
print "Problem getting address...\n";
}
(Last edited by gatorparrots; Jul 22, 2003 at 11:12 AM.
)
|
|
|
| |
|
|
|
 |
|
 |
|
Mac Enthusiast
Join Date: Jun 2000
Location: New Jersey, USA
Status:
Offline
|
|
Originally posted by Gary Kerbaugh:
ipconfig is installed by the Essentials.pkg installer package in /usr/sbin/ipconfig and ping is installed by the BaseSystem.pkg installer package in /sbin/ping.
Sorry, false alarm, I have both of them. I had stupidly expected that the finder search would find them. Argh.
Thanks for the help...
|
|
|
| |
|
|
|
 |
|
 |
|
Dedicated MacNNer
Join Date: Jul 2001
Location: NC
Status:
Offline
|
|
Ah, that's it. I love the Perl script but my router doesn't seem to have a status page of any type. It has only a web config page that's "so fancy" it only works on Windoze. :-( I can get the data via telnet and I could write an expect script to get it but that's complicated enough that I'd rather depend on one of these sites, if they work. Well, I'm glad it's back up ... really glad!
|
|
Gary
A computer scientist is someone who, when told to "Go to Hell", sees the
"go to", rather than the destination, as harmful.
|
| |
|
|
|
 |
 |
|
 |
|
|
|
|
|

|
|
 |
Forum Rules
|
 |
 |
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
|
HTML code is Off
|
|
|
|
|
|
 |
 |
 |
 |
|
 |
|