Author Topic: Terminal tool to get external and local IPs  (Read 1990 times)

0 Members and 1 Guest are viewing this topic.

Offline Kulverstukas

  • Administrator
  • Zeus
  • *
  • Posts: 6627
  • Cookies: 542
  • Fascist dictator
    • View Profile
    • My blog
Terminal tool to get external and local IPs
« on: December 09, 2011, 11:23:43 am »
Some days ago I made a little tool to get local and external IPs of your machine, but it was only for windows. I wanted something like that for my Linux as well, so I made this little bash script.
Put it into /bin/ folder and execute from anywhere with command: sh termip.sh

Script can always be found here: http://newage.ql.lt/projects/other/termip.sh

Code: [Select]
# Kulverstukas, http://newage.ql.lt/ ;; evilzone.org
# 2011
OS=`uname`
LocalIP=""
ExternIP=""
case $OS in Linux) LocalIP="Local IP   : "`ifconfig  | grep 'inet addr:'| grep -v '127.0.0.1' | cut -d: -f2 | awk '{ print $1}'`;;
            FreeBSD|OpenBSD) LocalIP="Local IP: "`ifconfig  | grep -E 'inet.[0-9]' | grep -v '127.0.0.1' | awk '{ print $2}'` ;;
            SunOS) LocalIP="Local IP   : "`ifconfig -a | grep inet | grep -v '127.0.0.1' | awk '{ print $2} '` ;;
            *) LocalIP="Local IP   : Unable to retrieve";;
esac

ExternIP="External IP: "`wget -qO- http://icanhazip.com`

echo "$LocalIP"
echo "$ExternIP"

Offline xzid

  • Knight
  • **
  • Posts: 329
  • Cookies: 41
    • View Profile
Re: Terminal tool to get external and local IPs
« Reply #1 on: December 09, 2011, 08:10:44 pm »
Put it into /bin/ folder

No.

http://www.pathname.com/fhs/pub/fhs-2.3.html

execute from anywhere with command: sh termip.sh

That command doesn't strike you as odd? Do you know the purpose of shebang lines? Add "#!/bin/sh" to the top of your script, remove the extension, chmod a+x your file.

http://bash.cyberciti.biz/misc-shell/read-local-ip-address/

your code is stolen(modified slightly) & you erased the copyright.

This is just flat out ugly:

Code: [Select]
ExternIP="External IP: "`wget -qO- http://icanhazip.com`
echo "$ExternIP"

# it should be either

ExternIP=`wget -qO- http://icanhazip.com`
echo "External IP: $ExternIP"

# or

echo "External IP: $(wget -qO- http://icanhazip.com)"

Giving my local ip isn't neccesary, ifconfig will reveal all I need. Your script can be reduced to a single command:

wget -qO- http://icanhazip.com

Offline Kulverstukas

  • Administrator
  • Zeus
  • *
  • Posts: 6627
  • Cookies: 542
  • Fascist dictator
    • View Profile
    • My blog
Re: Terminal tool to get external and local IPs
« Reply #2 on: December 09, 2011, 08:15:45 pm »
Thanks for clearing that out. I don't do bash scriptint at all so as I see here it looks ugly :P but it works...

Offline xzid

  • Knight
  • **
  • Posts: 329
  • Cookies: 41
    • View Profile
Re: Terminal tool to get external and local IPs
« Reply #3 on: December 09, 2011, 08:19:24 pm »
Thanks for clearing that out. I don't do bash scriptint at all so as I see here it looks ugly :P but it works...

Could you at least try to respond to anything I mentioned, like why its not OK the place your scripts inside /bin or how you thought it was OK to take someone elses code and put your name on it.

edit: >:( >:( >:(
« Last Edit: December 09, 2011, 08:19:50 pm by xzid »