Hack Forums
[Shell] Get Public | Private IP of your WiFi from Terminal [Linux] - Printable Version

+- Hack Forums (https://hackforums.net)
+-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444)
+--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151)
+---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118)
+---- Thread: [Shell] Get Public | Private IP of your WiFi from Terminal [Linux] (/showthread.php?tid=4889498)



Get Public | Private IP of your WiFi from Terminal [Linux] - rootsh3ll - Jul 1, 2015

Code
#! /bin/sh

public_IP()
{    pub_IP=$( wget -q -O - ifconfig.me/ip )

    if [ -z $pub_ip ]; then
        P_st="disconnected"
        P_ip="-"
    else
        P_ip="Public IP : $pub_IP"
        P_st="Connected"
    fi
}

private_IP()
{
    priv_IP=$(ifconfig wlan0 \
        | grep 'inet addr' \
        | cut -d: -f2 \
        | awk '{print $1}' )

    if [ -z $priv_IP ]; then
        p_ip="-"
        p_st="disconnected"
    else
        p_st="Connected"
        p_ip="$priv_IP"
    fi
}

help()
{
    echo "Usage : getip [OPTIONS]\n"
    echo "Options:\n -h\t: Help menu"
    echo " -p\t: Displays Private IP"
    echo " -P\t: Displays Public IP"
}

banner()
{
    echo "Private IP   |   Public IP   |   Internet Status\n "
}

start()
{
    if [ "$1" = '-h' ]; then
        help
    else
        banner
        private_IP
        public_IP
        echo "$p_ip\t\t$P_ip\t\t$P_st"
    fi
}

# Main function
start $@

Save the above code as getip.sh

then,

open terminal in curent directory and type
Quote:chmod u+x getip.sh
./getip.sh -h


just wait..and see the terminal will print back your Public and Private IP of you wireless Network.

FEEL FREE TO COMMENT IF YOU LIKE THE POST😉

--rootsh3ll @ ( rootsh3ll.com )