Page 3 of 5 FirstFirst 12345 LastLast
Results 21 to 30 of 47

Thread: HOWTO: Check you external IP Address from the command line

  1. #21
    Join Date
    May 2006
    Location
    Switzerland
    Beans
    2,907
    Distro
    Ubuntu 20.04 Focal Fossa

    Re: HOWTO: Check you external IP Address from the command line

    Sorry for necro-posting ... but in case someone finds this via Google just as I did, I'd like to add this little bit:

    I am a Dropbox user ... and Dropbox also exists for iPhone and Android phones ... so why not use Dropbox to record the external IP address? I could then check the IP via the web interface, or via my iPhone, or via any of my other computers that I sync with. Sounds like a good idea, doesn't it?

    Based on the previously made suggestions by all the other posters here (thanks guys!) I have added this nifty little cronjob to one of my "green PC's" (it only consumes around 10 Watts) that is constantly running, so it's a good candidate for this job:

    Code:
     */15 * * * * /usr/bin/wget http://www.whatismyip.com/automation/n09230945.asp -O - -q > /home/YourUserNameHere/Dropbox/ExternalIP/`hostname`.txt
    So this cronjob will run every 15 minutes and then output the external IP the system sees into a file that is located inside my Dropbox folder. The file will be named after the hostname this cronjob is running from.

    So I could have this cronjob on multiple systems and they would all report their external IP address back to me, no matter where they are.

    I hope this will be useful for anyone who finds this via Google ...

  2. #22
    Join Date
    Oct 2010
    Location
    England
    Beans
    Hidden!
    Distro
    Ubuntu 11.04 Natty Narwhal

    Re: HOWTO: Check you external IP Address from the command line

    Quote Originally Posted by motin View Post
    I hope you know about the possibility to find out your IP Address by using visiting the site http://www.whatismyip.com . I needed a way to check this from the command line and this is what I came up with:

    For this, you need the packages wget, grep and sed so make sure you have them by checking for them in Synaptic or running the following in a terminal:
    Code:
    sudo apt-get install wget grep sed
    Then, as long as whatismyip.com prints out the IP-Address in the HTML page title, you can use this:

    Create shell script:
    Code:
    cd ~
    mkdir bin
    nano  bin/whatismyip.sh
    Insert this into nano (Copy, then paste into nano by pressing Ctrl + Shift + V):
    Code:
    #!/bin/bash
    
    echo Your external IP Address is:
    wget http://Www.whatismyip.com -O - -o /dev/null | grep '<TITLE>' | sed -r 's/<TITLE>WhatIsMyIP\.com \- //g' | sed -r 's/<\/TITLE>//g'
    
    exit 0
    (You can also use gedit instead of nano, but I chose to use nano above in case this is done through a remote text-based connection)

    Press Ctrl + O, Enter, Ctrl + X, then run:
    Code:
    chmod u+x bin/whatismyip.sh
    Now you can check your external IP Address by running:
    Code:
    ~/bin/whatismyip.sh
    ...in a terminal.




    this is all well and good... But surely you can just go on to remote desktop and it shows you there!

  3. #23
    Join Date
    Nov 2007
    Location
    Wisconsin
    Beans
    1,139

    Re: HOWTO: Check you external IP Address from the command line

    All the cron-based approaches are a bit troubling - it can be rude to add unecessary load to somebody else's server. If you're not changing networks (laptop), you can also simply query your router. For me, it's about a second faster than using a foreign server.

    Code:
    wget -O - -o /dev/null http://192.168.1.1/Status_Router.asp --user=myRouterUserName --password=myRouterPassword | grep 'var wan_ip' | cut -d'"' -f2
    
    # wget             The command
    # -O -              Output the result to the screen, not a file
    # -o /dev/null    Strip the progress wget progress bars
    # http://192.168.1.1/Status_Router.asp    Use your appropriate router URL
    # --user=myRouterUserName                 Router authentication
    # --password=myRouterPassword 
    # | grep 'var wan_ip' | cut -d'"' -f2           Extract the IP address from the returned page
    Of course, the URL and grep string and formatting will vary by router.
    And it breaks when you change your router.
    And your router password is being sent in plain text.
    But in some situations that's preferable to repeatedly querying foreign IP addresses.




    Another approach to reduce your external bandwidth is to only check upon network-up (place a link to your script in /etc/network/if-up.d), though this only works if your external IP address doesn't change during your workday.

  4. #24
    Join Date
    Aug 2009
    Location
    India
    Beans
    Hidden!
    Distro
    Ubuntu Mate 16.04 Xenial Xerus

    Re: HOWTO: Check you external IP Address from the command line

    Why cant people use ifconfig to see their external ip?It takes only a couple of seconds.
    Last edited by karthick87; November 27th, 2010 at 11:50 AM.

  5. #25
    Join Date
    Nov 2007
    Location
    Wisconsin
    Beans
    1,139

    Re: HOWTO: Check you external IP Address from the command line

    If you are behind a router, ifconfig will only return the IP address on that network, which may not be the one you want.

    For example, if Uncle Claudio phones me and asks me to troubleshoot his problem, I must give him the IP address of my router in order to create the reverse-VNC connection. Ifconfig will give me the 192.*.*.* issued by my router, but he needs the public IP of my router, 75.*.*.*, issued by my ISP.

  6. #26
    Join Date
    Aug 2009
    Location
    India
    Beans
    Hidden!
    Distro
    Ubuntu Mate 16.04 Xenial Xerus

    Re: HOWTO: Check you external IP Address from the command line

    This is my output for ifconfig command it show's my public ip

    Code:
    karthick@Ubuntu-desktop:~$ ifconfig
    eth0      Link encap:Ethernet  HWaddr 00:1c:c0:ab:17:70  
              inet addr:192.168.1.10  Bcast:192.168.1.255  Mask:255.255.255.0
              UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
              RX packets:7955 errors:0 dropped:0 overruns:0 frame:0
              TX packets:7672 errors:0 dropped:0 overruns:0 carrier:0
              collisions:0 txqueuelen:1000 
              RX bytes:4956916 (4.9 MB)  TX bytes:1364829 (1.3 MB)
              Interrupt:27 Base address:0x6000 
    
    lo        Link encap:Local Loopback  
              inet addr:127.0.0.1  Mask:255.0.0.0
              UP LOOPBACK RUNNING  MTU:16436  Metric:1
              RX packets:4635 errors:0 dropped:0 overruns:0 frame:0
              TX packets:4635 errors:0 dropped:0 overruns:0 carrier:0
              collisions:0 txqueuelen:0 
              RX bytes:263899 (263.8 KB)  TX bytes:263899 (263.8 KB)
    
    ppp0      Link encap:Point-to-Point Protocol  
              inet addr:117.206.91.236  P-t-P:117.206.80.1  Mask:255.255.255.255
              UP POINTOPOINT RUNNING NOARP MULTICAST  MTU:1460  Metric:1
              RX packets:7522 errors:0 dropped:0 overruns:0 frame:0
              TX packets:7476 errors:0 dropped:0 overruns:0 carrier:0
              collisions:0 txqueuelen:3 
              RX bytes:4765234 (4.7 MB)  TX bytes:1183798 (1.1 MB)

  7. #27
    Join Date
    Jun 2009
    Location
    Indiana
    Beans
    85
    Distro
    Ubuntu 16.04 Xenial Xerus

    Re: HOWTO: Check you external IP Address from the command line

    karthick87 that is all well and good, if you have a PPP connection setup on your machine. Most users just have a router or modem that handle the login process for them. Many ISP's will pre-configure modems to handle the PPP connection. Many Cable company's don't even have logins for their network.
    =========================================

    We are drowning in information, but starved for knowledge....

  8. #28
    Join Date
    Aug 2009
    Location
    India
    Beans
    Hidden!
    Distro
    Ubuntu Mate 16.04 Xenial Xerus

    Re: HOWTO: Check you external IP Address from the command line

    @rbishop Thank you i got it now.

  9. #29
    Join Date
    May 2006
    Location
    Switzerland
    Beans
    2,907
    Distro
    Ubuntu 20.04 Focal Fossa

    Re: HOWTO: Check you external IP Address from the command line

    Quote Originally Posted by karthick87 View Post
    Why cant people use ifconfig to see their external ip?
    Good joke

    Quote Originally Posted by karthick87 View Post
    ppp0 Link encapoint-to-Point Protocol
    You know, in some regions of the world they have moved beyond PPP and dial-up like 12 or so years ago.

    You'd get a DSL or cable modem from your ISP (depending on your connection type) and that router/modem most of the time is also pre-configured to serve as DHCP server. So all you see via "ifconfig" is most likely that you got some RFC1918 private range address, usually 192.168.1.*-something, and that's it.

    So in order to find out your external IP (= the one behind your router/cable modem) you have to be a bit more creative than just using "ifconfig"

  10. #30
    Join Date
    Aug 2009
    Location
    India
    Beans
    Hidden!
    Distro
    Ubuntu Mate 16.04 Xenial Xerus

    Re: HOWTO: Check you external IP Address from the command line

    @scorp123 Thanks for the information

Page 3 of 5 FirstFirst 12345 LastLast

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •