Script visualizza numero IP

Guides, tutorials & docs
Post Reply
User avatar
Roberto_65
Collaboratore
Collaboratore
Posts: 516
Joined: 6 December 2007, 23:56
OpenMandriva: 2009.1
Kernel: i686 x86_64
Desktop: Gnome Xfce4
Location: Triangolo delle Bermude
Contact:

Script visualizza numero IP

Post 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/
Roberto_65
Packager delle MIB-Live
Il creatore delle MIB-Live
L'inventore di MIB-LiveToFlash
Triangolo delle Bermude http://www.sitohd.com/siti/3209

User avatar
Roberto_65
Collaboratore
Collaboratore
Posts: 516
Joined: 6 December 2007, 23:56
OpenMandriva: 2009.1
Kernel: i686 x86_64
Desktop: Gnome Xfce4
Location: Triangolo delle Bermude
Contact:

Re: Script visualizza numero IP

Post 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"'
Roberto_65
Packager delle MIB-Live
Il creatore delle MIB-Live
L'inventore di MIB-LiveToFlash
Triangolo delle Bermude http://www.sitohd.com/siti/3209

ominomichelin
Utente
Utente
Posts: 141
Joined: 28 March 2009, 18:19
OpenMandriva: 2009.1 x86_64
Kernel: 2.6.29.1

Re: Script visualizza numero IP

Post 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. ;)
http://www.mandrivausers.ro/ MRB aint no shit , :p Linux user number 507107 Nu dați banii pe prostii, puneți Linux pe PISI !

User avatar
MauRice
Utente
Utente
Posts: 185
Joined: 30 May 2008, 12:11
OpenMandriva: cooker
Contact:

Re: Script visualizza numero IP

Post 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
Registered Linux user: 473556
The Good, The Bad and The Ugly -> Linux, Windows e Dos
http://www.mandrivaclub.be

User avatar
NicCo
Amministratore
Amministratore
Posts: 4765
Joined: 6 December 2007, 19:54

Re: Script visualizza numero IP

Post by NicCo »

Applied, and I find that useful

Thanks
.
--- Professional experience ---
Kernel designer, engineer, maintainer and tester for ROSA Desktop and OpenMandriva Lx O.S.

--- currently I'm playing with ---
LTS Kernels > Linux 4.1.12-nrjQL <<< Linux 3.18.17-nrjQL <<< Linux 3.14.46-nrjQL
EOL Kernels > Linux 3.19.8-nrjQL <<< Linux 3.17.8-nrjQL <<< Linux 3.15.10-nrjQL

User avatar
MauRice
Utente
Utente
Posts: 185
Joined: 30 May 2008, 12:11
OpenMandriva: cooker
Contact:

Re: Script visualizza numero IP

Post 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
Registered Linux user: 473556
The Good, The Bad and The Ugly -> Linux, Windows e Dos
http://www.mandrivaclub.be

User avatar
MauRice
Utente
Utente
Posts: 185
Joined: 30 May 2008, 12:11
OpenMandriva: cooker
Contact:

Re: Script visualizza numero IP

Post 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....
Registered Linux user: 473556
The Good, The Bad and The Ugly -> Linux, Windows e Dos
http://www.mandrivaclub.be

Post Reply