Page 1 of 1

Script visualizza numero IP

Posted: 20 August 2011, 9:59
by Roberto_65
Questo script bash visualizza da terminale il numero IP della scheda di rete.

Avvolte serve estrarre solo il numero IP della scheda di rete e purtroppo non esiste alcun comando diretto, tranne ifconfig, ma estrae pure altre cose che non servono.
Questo script, di una sola riga, estrae il numero IP dal comando ifconfig e lo scrive dentro il file /etc/ip .

Code: Select all

#! /bin/bash
# /usr/bin/nip
# (C)-MIB
# Visualizza il numero IP della scheda di rete
#
if [ ! $1 ]; then
       echo; echo "SINTASSI: "$0" <Dev_Scheda_Rete>"
       echo "ESEMPIO: "$0" eth0"
       echo; exit 1
fi
ifconfig $1 | awk '/inet/ {print $2}'> /file.txt; i=$(cat /file.txt);rm -f /file.txt;i=${i:5};echo $i | awk '/addr/ {print $1}' > /etc/ip; i=$(cat /etc/ip);echo $i
Da creare un file nip e salvare in /usr/bin/

Re: Script visualizza numero IP

Posted: 20 August 2011, 12:43
by Roberto_65
RESERVED

http://lists.mandriva.com/cooker/2011-08/msg00259.php


E' possibile sostituire lo script con questo:

Code: Select all

ip addr | perl -n -e  '!/127\.0\.0\.1/ && /inet (\S*)\/\d+/ && print "$1\n"'

Re: Script visualizza numero IP

Posted: 26 August 2011, 19:50
by ominomichelin
Florian Hubold

Hello,

Cooker ML is an english mailing list, would be nice if you could
resend this message translated into english, so the non-italian speakers
can also understand. ;)

Re: Script visualizza numero IP

Posted: 1 October 2011, 12:38
by MauRice
A nice alternative.....
The script: http://users.telenet.be/x86_64/Scripts/IP.check
The place to put it, at the end of your hidden bashrc file

Each time you start Konsole, you have the output:
WAN: ip-adress
LAN: ip-adress

MauRice

Re: Script visualizza numero IP

Posted: 1 October 2011, 13:22
by NicCo
Applied, and I find that useful

Thanks

Re: Script visualizza numero IP

Posted: 1 October 2011, 15:04
by MauRice
No thanks NicCo,

The script is based on this site, http://www.watismijnip.nl/, to get the WAN ip-adress info.
The Italian equivalent: http://www.qualeilmioip.it/ (Is the literal translation)

MauRice

Re: Script visualizza numero IP

Posted: 2 October 2011, 8:02
by MauRice
For the bash script lovers....

Rewriting to work on the Italian equivalent:

Code: Select all

#WAN & LAN IP settings
myip ()
{
    INTERFACE=`cat /proc/net/arp | grep -m 1 -v Device | awk '{print $6}'`

    /usr/bin/wget -np -c www.qualeilmioip.it --output-document /tmp/index.html."$$" 2>/dev/null && export PRPID="$$"
    WAN_IP=`grep -i 'Il tuo IP' /tmp/index.html."$PRPID" | cut -d'-' -f2 | tr -d '[:blank:]' | cut -d'<' -f1`
    LAN_IP=`/sbin/ifconfig $INTERFACE | grep 'inet addr:' | cut -d: -f2 | cut -d' ' -f1 | tr -d '[:blank:]'`
    export {WAN,LAN}_IP && echo -en "\nWAN IP: $WAN_IP\n" && echo -en "LAN IP: $LAN_IP\n\n" && /bin/rm -f /tmp/index.html."$PRPID"
}

if ping -c 1 -w 1 www.google.it &>/dev/null; then
    myip;
else
    echo -en "\nThere is currently no\nConnection to the internet\nPlease check your settings! \n\n";
fi
Now you can figure it out how it works....