Skriptik na zjisteni IP adresy

OldFrog oldfrog na volny.cz
Neděle Srpen 25 02:44:40 CEST 2002


>
>
>Snazim se najit v archivu konference nejaky skriptik, ktery by mi
>poslal moji dynamickou adresu pri kazdem pripojeni na web ve forme
>smsky na mobil. Navede me nekdo spravnym smerem?
>

Zjisteni IP adresy (ze SuSE8.0):

===========/usr/bin/ipaddr================

#!/bin/sh
# ipaddr: look up the IP address of a network device
# Author: Christian Steinruecken
self=`basename $0`

while [ -n "$1" ]; do
  case "$1" in
  "-h"|"--help") cat <<EOF
Usage: ${self} [-i interface]
Prints the network IP address of the system to stdout. The network interface can 
be specified with the '-i' option. If omitted, the interface which is most likely
connected to the internet will be used.

EOF
exit 0
;;
  -i*|"--interface") shift;
    if [ -n "$1" ]; then
      netif="$1";
    else
      echo "${self}: option requires a parameter. See '${self} --help' for more info." >&2
      exit 1
    fi ;;
  -*) echo "${self}: unknown option '$1'." >&2; exit 1 ;;
  *) echo "${self}: unknown parameter. Try '--help'." >&2; exit 1 ;;
  esac
  shift
done

go() {
   /sbin/ifconfig | grep "$netif" -A 1 | tail -1 | awk '{print $2}' | sed "s/addr://"
}

ready=""
interfaces=`cat /proc/net/dev | tail +3 | sed "s/:.*//g"`
if [ -z "$netif" ]; then
  netif=`netstat -rn | grep "UG" | awk '{print \$8}'`
fi

if [ -n "$interfaces" ]; then
  for i in $interfaces; do
    if [ "$i" = "$netif" ]; then
      go
      ready="1"
    fi
  done
  [ -z "$ready" ] && echo "${self}: network device '$netif' not found." >&2
else
  go
fi

===========/usr/bin/ipaddr================

OldFrog.



Další informace o konferenci Linux