EvilZone
Programming and Scripting => Scripting Languages => : Kulverstukas December 09, 2011, 11:23:43 AM
-
Some days ago I made a little tool to get local and external IPs (http://evilzone.org/delphi-and-pascal/cmd-tool-to-get-external-and-local-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
# 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"
-
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:
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
-
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...
-
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: >:( >:( >:(