Page 5 of 5 FirstFirst ... 345
Results 41 to 47 of 47

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

  1. #41
    Join Date
    Oct 2006
    Beans
    Hidden!

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

    Quote Originally Posted by Khayyam View Post
    necromancy .. mia culpa!

    I see alot of 'grep | cut | awk' etc .. all of this can by achieved with one command:

    Code:
    awk '/inet addr:/{print (substr($2,6,15))}' <(ifconfig eth0)
    or similarly to preface it with 'eth0 IP:'

    Code:
    awk '/inet addr:/ {print "eth0 IP: "(substr($2,6,15))}' <(ifconfig eth0)
    HTH ... khay
    Why invoking awk or any external command if plain POSIX shell already can do this:

    Code:
    ifconfig eth0|{ IFS=' :';read r;read r r a r;echo $a;}
    or similarly to preface it with 'eth0 IP:'

    Code:
    ifconfig eth0|{ IFS=' :';read r;read r r a r;echo "eth0 IP: $a";}
    Ciao - linuxball

  2. #42
    Join Date
    Oct 2008
    Beans
    3,509

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

    Quote Originally Posted by linuxball View Post
    Why invoking awk or any external command if plain POSIX shell already can do this:

    Code:
    ifconfig eth0|{ IFS=' :';read r;read r r a r;echo $a;}
    or similarly to preface it with 'eth0 IP:'

    Code:
    ifconfig eth0|{ IFS=' :';read r;read r r a r;echo "eth0 IP: $a";}
    Ciao - linuxball
    Just gives my LAN address.

  3. #43
    Join Date
    Oct 2006
    Beans
    Hidden!

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

    Quote Originally Posted by stinkeye View Post
    Just gives my LAN address.
    You are right. My message was just a reply to message #37 (which admittedly was off-topic) of this thread.

    My point was that the built-in features of the used POSIX shell mostly suffice to do post-processing. E.g. two examples which match the topic:
    Code:
    a=$(curl -s checkip.dyndns.org); a=${a##* }; echo ${a%%<*}
    Code:
    a=$(curl -s ipogre.com/linux.php); a=${a##* }; echo ${a%%<*}
    The above examples will work in /bin/bash and /bin/sh (dash and other POSIX-compliant shells).

    Instead of "curl -s" one can use "wget -qO -".

    Ciao - linuxball

  4. #44
    Join Date
    Apr 2012
    Beans
    2

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

    IP Address:

    Code:
    curl ipogre.com
    Hostname:

    Code:
    curl ipogre.com/host
    User-agent (browser information):

    Code:
    curl ipogre.com/ua
    Client Source Port (What port is the client using to access ipogre.com)

    Code:
    curl ipogre.com/port

  5. #45
    Join Date
    Jul 2008
    Beans
    46

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

    Quote Originally Posted by linuxball View Post
    You are right. My message was just a reply to message #37 (which admittedly was off-topic) of this thread.

    My point was that the built-in features of the used POSIX shell mostly suffice to do post-processing. E.g. two examples which match the topic:
    Code:
    a=$(curl -s checkip.dyndns.org); a=${a##* }; echo ${a%%<*}
    Code:
    a=$(curl -s ipogre.com/linux.php); a=${a##* }; echo ${a%%<*}
    The above examples will work in /bin/bash and /bin/sh (dash and other POSIX-compliant shells).

    Instead of "curl -s" one can use "wget -qO -".

    Ciao - linuxball
    exquisitely elegant ... thanx for teaching me ## && %%

  6. #46
    Join Date
    Jul 2008
    Beans
    46

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

    That is good for this:
    Code:
    a=$(curl -s checkip.dyndns.org); a=${a##*\.}; a=${a%%<*};color="\033[38;5;${a}m";plain="\033[0m";export PS1="\[${color}\]${PS1}\[${plain}\]"

  7. #47
    Join Date
    Oct 2013
    Beans
    6

    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.
    Well ! the following code is used to find ip address :

    ifconfig | grep -E 'inet.[0-9]' | grep -v '127.0.0.1' | awk '{ print $2}'

    Usually, i use Ip-details.com to get extarnal ip address .





Page 5 of 5 FirstFirst ... 345

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
  •