Page 2 of 5 FirstFirst 1234 ... LastLast
Results 11 to 20 of 47

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

  1. #11
    Join Date
    Aug 2005
    Location
    Ohio
    Beans
    60
    Distro
    Ubuntu 8.04 Hardy Heron

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

    Try this:

    Code:
    curl www.whatismyip.org
    Main Rig: Athlon XP 2800+ (Overclocked) | 512MB Corsair DDR400 Dual Channel | Asus A7N8X Deluxe | ATi Radeon 9700 Pro
    Linux Registered User - #423753

  2. #12
    Join Date
    Mar 2007
    Location
    /US/EC/DC
    Beans
    Hidden!

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

    The last 2 posters should hit:

    http://whatismyip.com/automation/n09230945.asp

    Especially if you're using this in Conky. No need to put undue strain on their servers, and it doesn't have a restriction (or it has a much higher one) on hits in a specific time period.
    Warranty? Who needs a warranty?
    If it ain't broke, take it apart and fix it.

  3. #13
    Join Date
    Mar 2007
    Location
    Denver, CO
    Beans
    7,552
    Distro
    Ubuntu 12.04 Precise Pangolin

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

    What about this:

    wget -q -O - checkip.dyndns.org | sed -e 's/[^[:digit:]|.]//g'

    That seems simple enough for me. That will give you your external IP address.

  4. #14
    Join Date
    Oct 2007
    Beans
    10

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

    This is how i did it:

    Code:
    sudo gedit /bin/whatsmyip.sh
    Paste the following:

    Code:
    #!/bin/bash
    
    echo
    echo "---External IP:  "
    wget www.whatismyip.com/automation/n09230945.asp -O - -q
    echo
    echo
    echo "---Internal IP: "
    ifconfig | grep 'inet addr:'| grep -v '127.0.0.1' | cut -d: -f2 | awk '{ print $1}'
    echo
    
    exit 0
    Press save and exit then:
    Code:
    sudo chmod 777 /bin/whatsmyip.sh
    next:
    Code:
    sudo gedit /home/"your username here"/.bashrc
    Paste this in the end of .bashrc file:

    Code:
    # Own Scripts
    	alias whatsmyip='/bin/whatsmyip.sh'
    log out and in again.

    Now you can see both your internal and external ip by typing:

    Code:
    whatsmyip
    You can alter the alias in the .bashrc file to whatever you feel like if you're inconvenient with "whatsmyip"

  5. #15
    Join Date
    Mar 2008
    Beans
    28

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

    Thanks, tturrisi for your example.

  6. #16
    Join Date
    Feb 2008
    Beans
    5

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

    Hi All,

    I tried to run the script, but sendmail is not working !

    Can anybody point me to the right direction ??

    The error is like the following :

    Error starting sendmail: No such file or directory at /usr/bin/email_ip.sh line 17.

    TQ for your help in advance.

    Regards

    Casey


    Quote Originally Posted by c8h10n4o2 View Post
    I know this is an old post but I would like to say thanks for the help. I've been trying to figure out how to traceroute. This is much simpler.

    Just in case anyone wants it, I've created the following PERL script I keep in cron to check my IP and compare it to the previous and email me if it has changed.

    Code:
    #!/usr/bin/perl
    $IP_FILE = "/home/c8h10n4o2/scripts/ipemail.result";
    my $newip = `wget www.whatismyip.com/automation/n09230945.asp -O - -q`;
    my $oldip = getoldip();
    my $send_to = "To: me\@me.com\n";
    my $reply_to = "Reply-to: me\@me.com\n"; 
    my $from = "From: me\@me.com\n";
    my $subject = "Subject: IP Address: $newip\n"; 
    my $content = "<h1>$newip</h1>"; 
    if($newip ne $oldip)
    {
       writenewip($newip);
       unless(open (MAIL, "|/usr/sbin/sendmail me\@me.com")) 
       {
          print "error.\n";
          warn "Error starting sendmail: $!";
       }
       else{
          print MAIL $from;
          print MAIL $reply_to;
          print MAIL $subject;
          print MAIL $send_to;
          print MAIL "Content-type: text/html\n\n";
          print MAIL $content;
          close(MAIL) || warn "Error closing mail: $!";
          print "Mail sent\n";
       }
    }
    
    sub writenewip
    {
       my($newip) = @_;
       print ("new IP = $newip\n");
       open IPFILE, ">$IP_FILE";
       print IPFILE "$newip\n";
       close IPFILE;
    }
    
    sub getoldip
    {
       open IPFILE, "$IP_FILE";
       my($line) = 0;
       while ( <IPFILE> )
       {
          chomp;
          $line = $_;
       }
       close IPFILE;
       return($line);
    }

  7. #17
    Join Date
    Feb 2008
    Beans
    5

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

    Bro,

    I just realize that I did not have sendmail install and now it show the IP and show Email sent also !!

    However, the problem now is that I did not get the mail in my gmail a/c ??

    Not in the SPAM box either !

    Can someone shed some light !

    TQ and regards,

    Casey

  8. #18
    Join Date
    Jul 2006
    Location
    Abuja, Nigeria
    Beans
    Hidden!
    Distro
    Ubuntu 12.04 Precise Pangolin

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

    Nice work folks...

    try the code below just for fun ... it appears/seems better formatted.

    #!/bin/bash
    echo
    echo " External IP: `wget www.whatismyip.com/automation/n09230945.asp -O - -q echo `"
    echo " Internal IP: `ifconfig | grep 'inet addr:'| grep -v '127.0.0.1' | cut -d: -f2 | awk '{ print $1}'`"
    echo
    exit 0

    Keep up the good deeds
    Ecclesiastes 3

  9. #19
    Join Date
    Dec 2008
    Location
    /home
    Beans
    19
    Distro
    Ubuntu 9.04 Jaunty Jackalope

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

    looking for the same thing I found that I can put this in my .bashrc file
    alias out='wget -qO - http://cfaj.freeshell.org/ipaddr.cgi'
    (obviously because 'in' is ifconfig)

    You all have some nice scripts too, thanx

  10. #20
    Join Date
    Mar 2007
    Beans
    17

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

    Hi, I'm raising this topic back to life because I'm too proud of the simplest thing I just made up.

    I wanted to always know what was the wan IP of my home PC when I'm using my netbook anywhere else. And since I'm using Ubuntu One to instantly share small files from both, this is what I came up with:

    1) Run crontab -e to edit your crontab file (cron runs commands periodically as ordered).
    2) Add this line at the bottom:
    * * * * * wget -rnH http://checkip.dyndns.org/ -P /home/USER/U1-SHARED-FOLDER

    3) Save and enjoy...

    ...obviously replacing "user" and "U1-Shared-Folder" for your real folders.
    The asteriscs at the beginning mean "every minute/hour/day/month/day-of-week". Since Ubuntu One will only sync it out when the local file changes in content, this doesn't create any distinguishable resource drain, at least on my PC here.
    You can set proper numbers if you want to go slower: for example 0 * * * 1 for hourly, o'clock, but only on mondays... Choice is yours.


    Then, on every PC that shares the Shared Folder, there will be a copy of and "index.html" file with the IP stored, adapting its content in little more than a minute of delay...

Page 2 of 5 FirstFirst 1234 ... 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
  •