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 > get the current active IP address(es)?

get the current active IP address(es)?
Thread Tools
fortepianissimo
Senior User
Join Date: Nov 2002
Location: US
Status: Offline
Reply With Quote
Nov 13, 2003, 02:11 PM
 
I know it can be done by parsing ifconfig output, or do a reverse DNS lookup based on hostname. But

1. I want to get the IP address of the DEFAULT outward connection (we could have multiple active IP addresses at a time)

2. It might be the case that the machine doesn't have a valid domain name

Any suggestion is welcome!
     
arekkusu
Mac Enthusiast
Join Date: Jul 2002
Status: Offline
Reply With Quote
Nov 13, 2003, 06:51 PM
 
alias wanip='curl -s http://checkip.dyndns.org/ | egrep '\''[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+'\'' | cut -d'\'' '\'' -f4 | cut -d'\''<'\'' -f1'
     
fortepianissimo  (op)
Senior User
Join Date: Nov 2002
Location: US
Status: Offline
Reply With Quote
Nov 13, 2003, 09:04 PM
 
Originally posted by arekkusu:
alias wanip='curl -s http://checkip.dyndns.org/ | egrep '\''[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+'\'' | cut -d'\'' '\'' -f4 | cut -d'\''<'\'' -f1'
Thank you, but this has two problems:

1. it relies on an external site (what if the site is down?);

2. it doesn't work behind an NAT'ed machine (i.e., in a home LAN I might want to know the masq'ed IP, not the IP of the gateway connecting to the external world).
     
utidjian
Senior User
Join Date: Jan 2001
Location: Mahwah, NJ USA
Status: Offline
Reply With Quote
Nov 14, 2003, 10:31 AM
 
Originally posted by fortepianissimo:
Thank you, but this has two problems:

1. it relies on an external site (what if the site is down?);

2. it doesn't work behind an NAT'ed machine (i.e., in a home LAN I might want to know the masq'ed IP, not the IP of the gateway connecting to the external world).
It is a little unclear what it is you actually want. Usually, "the IP address of the DEFAULT outward connection" is the default gateway. IOW on a LAN where all the IPs of the LAN machines are in some private range (such as 192.168.1.1 - 192.168.1.254) each of the machines with one or more of those IPs will have to know how to talk to the outside world... not just each other.

If you have a router... it will most likely have an "internal" IP within the range listed above (not always). For instance, on my home network my router has the IP address 192.168.1.253. I actually have more than one router BUT all machines use the one that has the .253 IP. For the internal machines on the LAN they all point to 192.168.1.253 as their default gateway.

The router, naturally, has at least two IPs and at least two interfaces (NICs). Each interface has an IP assigned to it.

Now... on the internal machines (clients), the ones on your LAN... they will have their IP addresses either statically assigned or dynamically assigned (via DHCP). Usually the dynamic IP comes from the router (the router is a DHCP server). The LAN machines also get their default gateway IP and DNS IPs from the DHCP server on the router. It doesn't have to be this way but it usually is this way. You could have a separate DHCP server on the LAN (as I do). In either case... the usual setup for the LAN clients is they get their IP address, default gateway, and DNS IPs from the DHCP server.

On most home LANs the router behaves similarly. It gets its *external* IP address, default gateway, and DNS IPs from your ISPs DHCP server... the *internal* IP address of the router is usually static (typically 192.168.1.1). Depending on how the router is set up and how the ISP does things the *external* IP, default gateway, and DNS IPs may change over time and the router may or may not update this information as the ISP makes changes. It does this via DHCP.

How to determine what is going on....
For your internal Mac OS X clients:

* To determine client IP address(es):
ifconfig -a
which will give you the IP address of all interfaces on the client machine.

* To determine client routing table:
netstat -r
which will tell you how packets are routed to/from the client machine. See the manpage for netstat for all the details. Usually the default gateway is the first entry in the list.

For your router (if you have access):

* You will need access to the router. If your router is a Mac OS X machine then you can use the same commands as above.

* If it is a dedicated appliance router/switch then access is usually via a web interface... just browse to it. Consult your router manual on how to look up the info you need.

For your router (if you DON'T have access):

* If you do not have access to the router or it is a really dumb router it will be a bit more difficult to figure out what the *external* IP address of the router is. Many Unix based systems (Linux/BSD/Mac OS X/Solaris/etc) have a simple utility such as "w". Just ssh to an external Unix based host and type a single w at the prompt and it will tell you who is logged on and from *where*. The *where* part is under the "From" column and is either a fully qualified domain name or an IP address.

* If you are trying to figure out the *external* address of the router AND you are not on your home LAN... say, somwhere out in the world... then ssh to a system that you recently accessed via ssh *from* your home LAN and, depending on the system, it will give you the IP or FQDN that you last sshed from. Alternatively just type "last" and it will give you a list of IPs/FQDNs that you last logged in from.

Note: For "dumb" or inaccessible routers the above methods are kinda kludgy but they do work. There are may be many other methods... even slicker ones.

Hope that helps.
-DU-...etc...
     
   
 
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 07:38 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.,