|
|
How to find IP address from command-line?
|
|
|
|
Senior User
Join Date: Apr 2001
Location: Victoria, Australia
Status:
Offline
|
|
Hi All,
Before installing OSX10.1.2, I could determine the current IP address of my cable connection from the command-line via:
/usr/sbin/ipconfig getifaddr en0
As of 10.1.2, this now gives me an error:
get if addr en0 failed, (os/kern) failure
Any idea what is going on? Any suggestions on other command-line ways to determine the IP address?
Thanks.
|
|
|
|
|
|
|
|
|
Dedicated MacNNer
Join Date: May 2001
Status:
Offline
|
|
ifconfig -a
returns all ip addresses and other information about all your network devices
or type "man ifconfig" for more info
|
|
|
|
|
|
|
|
|
Dedicated MacNNer
Join Date: Apr 2001
Location: World capital of drugs and prostitution. Hmmm... SEXTC...
Status:
Offline
|
|
If you want just the IP address, then do:
<font face = "courier">ifconfig -a | grep inet | grep -v 127.0.0.1|awk '{print $2}'</font>
This way you filter out all the less important info from the ifconfig command.
|
The one you love and the one who loves you are never the same person.
|
|
|
|
|
|
|
|
Dedicated MacNNer
Join Date: Jul 2001
Location: NC
Status:
Offline
|
|
Actually, I find that the following returns the IP address (numbers only)
ifconfig en0 | awk '/inet/{print $2}'
and since it involves only a single call to awk, (no grep) it might be a little faster. HTH
|
Gary
A computer scientist is someone who, when told to "Go to Hell", sees the
"go to", rather than the destination, as harmful.
|
|
|
|
|
|
|
|
Mac Enthusiast
Join Date: Apr 2001
Location: Ottawa, ON, Canada
Status:
Offline
|
|
Originally posted by curmi:
<STRONG>Hi All,
Before installing OSX10.1.2, I could determine the current IP address of my cable connection from the command-line via:
/usr/sbin/ipconfig getifaddr en0
As of 10.1.2, this now gives me an error:
get if addr en0 failed, (os/kern) failure
</STRONG>
Whilst a couple of workarounds have been posted below, this is a bug. Please report it to apple, so it can be fixed.
I think this may be related to nettools now being out of sync with the kernel, but not 100% sure.
Cheers.
Ben.
|
|
|
|
|
|
|
|
|
Fresh-Faced Recruit
Join Date: May 2000
Location: Mountain View, CA
Status:
Offline
|
|
Yet another way of getting the IP address(es):
AppleSystemProfiler | grep IP
|
|
|
|
|
|
|
|
|
Mac Elite
Join Date: Sep 2000
Location: Edmond, OK USA
Status:
Offline
|
|
That's weird - when did AppleSystemProfiler become a CL tool?
|
|
|
|
|
|
|
|
|
Fresh-Faced Recruit
Join Date: Oct 2000
Location: Livermore, CA
Status:
Offline
|
|
I don't know when AppleSystemProfiler became a CL tool, but make sure you capitalize the ASP! It will work in situations where the GUI ASP will crash and tell you nothing- at least the CLI ASP will crank out info until it fails, and the info that is left can be read after it goes south, if it does. A handy thing to know. I use it more than the GUI one...
Dave
|
|
|
|
|
|
|
|
|
Mac Enthusiast
Join Date: Oct 2000
Status:
Offline
|
|
Originally posted by absmiths:
<STRONG>That's weird - when did AppleSystemProfiler become a CL tool?</STRONG>
at least since macos x public beta (and probably before).
|
|
|
|
|
|
|
|
|
Mac Elite
Join Date: Dec 2001
Location: Atlanta, GA, USA
Status:
Offline
|
|
That is an awesome tip!
I can think of all sorts of good uses for that. Here are the command-line options for it:
<BLOCKQUOTE><font size="1"face="Geneva, Verdana, Arial">code:</font><HR><pre><font size=1 face=courier>
[dshaw@iceman ~/Downloads] AppleSystemProfiler -h
usage: AppleSystemProfiler [-[adefhmopuw]]
where options are:
-a show all information (the default if no options specified)
-d show drive information (location and volumes connected)
-e show Ethernet information (similar to ifconfig)
-f show FireWire information
-h show this usage information
-m show memory information (total amount, how much is in each slot)
-o show hardware summary (information not shown by d, e, f, m, p, and u options)
-p show PCI card information
-u show USB information
-w <path> Use the code bundle from <path>. Default is /Applications/Utilties/Apple System Profiler.app/
</font>[/code]
|
Mac Pro 2x 2.66 GHz Dual core, Apple TV 160GB, two Windows XP PCs
|
|
|
|
|
|
|
|
Dedicated MacNNer
Join Date: Oct 2001
Location: Baltimore, MD, US
Status:
Offline
|
|
|
|
|
|
|
|
|
|
|
Senior User
Join Date: Dec 1999
Location: Bar Harbor
Status:
Offline
|
|
Originally posted by Ununnilium:
<STRONG>Yet another way of getting the IP address(es):
AppleSystemProfiler | grep IP</STRONG>
This also found my Zip drive.
Very cool tool from the command line indeed!
|
I'm cookoo for Cocoa Apps!
|
|
|
|
|
|
|
|
Fresh-Faced Recruit
Join Date: Oct 2001
Location: Japan
Status:
Offline
|
|
Originally posted by curmi:
<STRONG>Hi All,
Before installing OSX10.1.2, I could determine the current IP address of my cable connection from the command-line via:
/usr/sbin/ipconfig getifaddr en0
As of 10.1.2, this now gives me an error:
get if addr en0 failed, (os/kern) failure
Thanks.</STRONG>
You're using en1 interface, probably. A good way to get the ip address is:
<BLOCKQUOTE><font size="1"face="Geneva, Verdana, Arial">code:</font><HR><pre><font size=1 face=courier>
#!/bin/sh
ifconfig en1 | awk '/inet/{print $<font color = blue>2</font>}'
ifconfig -a | grep inet | grep -v <font color = blue>127.0</font>.<font color = blue>0.1</font>|awk '{print $<font color = blue>2</font>}'
</font>[/code]
|
|
|
|
|
|
|
|
|
Moderator Emeritus
Join Date: Mar 2001
Location: Austin, MN, USA
Status:
Offline
|
|
Originally posted by jcarr:
<STRONG>This also found my Zip drive. </STRONG>
Yep, me too. Therefore to fix that, we type:
<font face = "courier">AppleSystemProfiler -e | grep IP</font>
Voila!
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
|
|
|