Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > macOS > How to find IP address from command-line?

How to find IP address from command-line?
Thread Tools
curmi
Senior User
Join Date: Apr 2001
Location: Victoria, Australia
Status: Offline
Reply With Quote
Dec 22, 2001, 02:45 AM
 
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.
     
gee308
Dedicated MacNNer
Join Date: May 2001
Status: Offline
Reply With Quote
Dec 22, 2001, 08:03 AM
 
ifconfig -a
returns all ip addresses and other information about all your network devices
or type "man ifconfig" for more info
     
Jelle Monkmater
Dedicated MacNNer
Join Date: Apr 2001
Location: World capital of drugs and prostitution. Hmmm... SEXTC...
Status: Offline
Reply With Quote
Dec 22, 2001, 09:31 AM
 
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.
     
Gary Kerbaugh
Dedicated MacNNer
Join Date: Jul 2001
Location: NC
Status: Offline
Reply With Quote
Dec 22, 2001, 10:12 PM
 
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.
     
Brit Ben
Mac Enthusiast
Join Date: Apr 2001
Location: Ottawa, ON, Canada
Status: Offline
Reply With Quote
Dec 24, 2001, 12:42 PM
 
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.
     
Ununnilium
Fresh-Faced Recruit
Join Date: May 2000
Location: Mountain View, CA
Status: Offline
Reply With Quote
Dec 29, 2001, 05:53 AM
 
Yet another way of getting the IP address(es):

AppleSystemProfiler | grep IP
     
absmiths
Mac Elite
Join Date: Sep 2000
Location: Edmond, OK USA
Status: Offline
Reply With Quote
Jan 3, 2002, 04:28 PM
 
That's weird - when did AppleSystemProfiler become a CL tool?
     
Glasspusher
Fresh-Faced Recruit
Join Date: Oct 2000
Location: Livermore, CA
Status: Offline
Reply With Quote
Jan 3, 2002, 05:24 PM
 
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
     
rkt
Mac Enthusiast
Join Date: Oct 2000
Status: Offline
Reply With Quote
Jan 5, 2002, 08:10 AM
 
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).
     
Arkham_c
Mac Elite
Join Date: Dec 2001
Location: Atlanta, GA, USA
Status: Offline
Reply With Quote
Jan 8, 2002, 02:27 PM
 
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 &lt;path&gt; Use the code bundle from &lt;path&gt;. 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
     
petej
Dedicated MacNNer
Join Date: Oct 2001
Location: Baltimore, MD, US
Status: Offline
Reply With Quote
Jan 9, 2002, 10:26 PM
 
netstat -ni
     
jcarr
Senior User
Join Date: Dec 1999
Location: Bar Harbor
Status: Offline
Reply With Quote
Jan 10, 2002, 10:20 AM
 
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!
     
kungfoo
Fresh-Faced Recruit
Join Date: Oct 2001
Location: Japan
Status: Offline
Reply With Quote
Jan 10, 2002, 07:33 PM
 
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]
     
Xeo
Moderator Emeritus
Join Date: Mar 2001
Location: Austin, MN, USA
Status: Offline
Reply With Quote
Jan 13, 2002, 12:37 AM
 
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!
     
   
Thread Tools
 
Forum Links
Forum 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
Top
Privacy Policy
All times are GMT -4. The time now is 11:31 PM.
All contents of these forums © 1995-2017 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.8 © 2000-2017, Jelsoft Enterprises Ltd.,