terminal: get IP address

Discussion in 'Mac Applications and Mac App Store' started by sonofslim, Mar 13, 2004.

  1. macrumors 6502a

    sonofslim

    Joined:
    Jun 6, 2003
    #1
    is there a terminal command that will display your external IP address? ifconfig and netstat only seem to report my local/network address, so i've been using curl and awk to parse http://checkip.dyndns.org. but i'd prefer a way that doesn't rely on an http call. not to mention that my method will fail if/when dyndns changes the format of that page.

    any ideas?
     
  2. Moderator emeritus

    edesignuk

    Joined:
    Mar 25, 2002
    Location:
    London, England
    #2
    if all you want to know is your WAN IP address http://www.whatismyip.com should do the job for you, it has been online for an age, and I can't see anyone changing it anytime soon.
     
  3. macrumors 601

    Westside guy

    Joined:
    Oct 15, 2003
    Location:
    The soggy part of the Pacific NW
    #3
    I'm a bit confused - are you behind a NAT firewall? ifconfig should report your IP address just fine.

    I realize this is just nit-picking, but if your NAT-ted then what you're probably looking for is the IP of the router/firewall rather than your own. If that's the case you can usually get it from the router's Web interface (assuming it has one, and most do).
     
  4. thread starter macrumors 6502a

    sonofslim

    Joined:
    Jun 6, 2003
    #4
    yes, that's the case. is there any way to get my router's external IP address from the terminal?
     
  5. macrumors 6502a

    Joined:
    Jul 22, 2002
    Location:
    Tacoma, WA
    #5
    I think your best bet is to do a traceroute of a packet ping (so it sends back to you). This will report both the outgoing (not too helpful) and return trip (where you will find your IP).

    BEN
     
  6. macrumors 6502

    Joined:
    Dec 25, 2001
    #6
    try ifconfig

    yes ifconfig, not ipconfig

    Here is a more detailed look at network commands for UNIX, LINUX, and DOS.
     
  7. thread starter macrumors 6502a

    sonofslim

    Joined:
    Jun 6, 2003
    #7
    see above: ifconfig gives me my local network IP. but the link you sent was pretty helpful -- thanks.

    sorry, i can't figure out how to combine traceroute & ping... any clues?
     
  8. macrumors newbie

    Joined:
    Feb 5, 2010
    #8
    try this in a console window (ensure that cURL is installed) :

    Code:
    curl -s http://checkip.dyndns.org | sed 's/[a-zA-Z/<> :]//g'
     
  9. JNB
    macrumors 604

    JNB

    Joined:
    Oct 7, 2004
    Location:
    In a Hell predominately of my own making
    #9
    Six year old thread. You win! :D
     
  10. macrumors newbie

    Joined:
    Sep 14, 2008
    #10
    Help

    Yes, it is six years old, but as the original poster asked, is there a way, from behind an Airport Extreme, Express, or Time Capsule, to determine your WAN IP address, without relying on an external source, such as checkip.dyndns.org or whatsmyip.com?

    It has been six years and maybe something has come around that will now help us to do this?

    I appreciate any suggestions on accomplishing this locally as originally asked.
     
  11. macrumors newbie

    Joined:
    Jul 10, 2010
    #11
    External IP address via Terminal

    Try this:


    curl ifconfig.me/all/json
     
  12. macrumors newbie

    Joined:
    Sep 14, 2008
    #12
    Perfect! Now I can create a shell script to parse the external address and compare it to a saved address without having to bother whatismyip.com with unnecessary calls. I appreciate it! :D
     
  13. macrumors 68040

    Joined:
    Jul 11, 2009
    #13
    Instead, you're "bothering" ifconfig.me as it's a website too. What's the difference?
     
  14. macrumors newbie

    Joined:
    Sep 14, 2008
    #14
    I did not realize that. I thought the ifconfig.me was just a function of the ifconfig command.

    That still doesn't do what I want then, nor the original poster. I'll keep looking. Thank you for your response.
     
  15. macrumors newbie

    Joined:
    Sep 14, 2008
    #15
    Ok, after doing some more research, I have found a way to get the external IP address from an Airport Extreme or Time Capsule (which is what I have) and I don't see why this wouldn't work for any other router that supports SNMP.

    From the terminal do this:

    prompt$ snmpwalk -Os -c {community name assigned to your device} -v 1 {private ip i.e. 192.168.1.1} ipAdEntAddr

    The result for me is:
    ipAdrEnt.xxx.xxx.xxx.xxx = IpAddress: xxx.xxx.xxx.xxx
    ipAdrEnt.127.0.0.1 = IpAddress: 127.0.0.1
    ipAdrEnt.127.0.0.2 = IpAddress: 127.0.0.2
    ipAdrEnt.169.254.12.117 = IpAddress: 169.254.12.117
    ipAdrEnt.192.168.1.1 = IpAddress: 192.168.1.1

    Now all I need to do is parse this the way I want it and I no longer have to ping an external web site to determine my own external IP address.

    I believe this answers the original posters question.
     
  16. macrumors newbie

    Joined:
    Oct 22, 2011
    #16
    The reply to this question is there are no such terminal command and/or software of OS that can tell your external IP address (i.e. your "location" in internet) without using external resources (e.g. some other computers).

    The reason is simple. It's like asking from your computer where it's located without plugging it in to the internet..
    When the computer was just manufactured in the factory and OS was just clean installed on it, it doesn't know your IP address, before you buy this particular computer.. what if someone else bought this particular computer? that would mean that any picked computer has to know all existing external IP addresses and intelligently decide which IP belongs to which guy and also keep in mind that that guy's ISP also changes it from time to time...

    That's why you use another server to "bounce" your IP address from as in:
    http://www.whatismyip.com
    or
    curl ifconfig.me/all/json

    You also can write a program, which you will be able to run in terminal by just one word, but it still will have to use "external" resources to find out about your external ip address..
     
  17. macrumors newbie

    Joined:
    Sep 14, 2008
    #17
    You are partially correct in that you do need an external resource other than the computer. In my case it is my SNMP compatible router.

    What the original poster wanted to do was similar to what I have been successful at. I wanted/needed my router's external IP address and I need to check the IP periodically because my router does not support the dynamic IP service I use. Rather than using http calls and creating traffic (albeit minimal) I wanted something internal to my network that would be able to determine whether or not my dynamic IP address has changed and if so I then reach out to my registrar and update the DNS with the new IP address.

    I don't think (my assumption) the OP was asking how to determine the Internet IP address (location) of a computer that has been purchased, set up, and turned on for the first time without connecting it to the Internet.
     

Share This Page