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

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
    Location
    Woop Woop
    Beans
    3,120
    Distro
    Ubuntu Development Release

    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.
    ɹǝpun uʍop puɐl ɐ ɯoɹɟ ǝɯoɔ ı
    ɹǝpunɥɔ uǝɯ puɐ ʍolɟ sǝop ɹǝǝq ǝɹǝɥʍ

  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
    44

    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
    44

    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}\]"

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
  •