Hi Zach,

Well, this almost works for me.

#!perl
my $ifconfig = `ifconfig`; # the ifconfig command gives the current network information
$ifconfig =~ /inet (\d+\.\d+\.\d+\.\d+)/; # extract the ip address with a regular expression
This does extract my IP address, but the one for the loopback device lo0. The ifconfig output looks like this:

lo0: flags=8049<UP,LOOPBACK,RUNNING,MULTICAST> mtu 16384
inet6 ::1 prefixlen 128
inet6 fe80::1 prefixlen 64 scopeid 0x1
inet 127.0.0.1 netmask 0xff000000
gif0: flags=8010<POINTOPOINT,MULTICAST> mtu 1280
stf0: flags=0<> mtu 1280
en0: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1500
tunnel inet -->
ether 00:30:65:ef:a8:f0
media: autoselect (10baseT/UTP <half-duplex>) status: active
supported media: none autoselect 10baseT/UTP <half-duplex> 10baseT/UTP <full-duplex> 10baseT/UTP <full-duplex,hw-loopback> 100baseTX <half-duplex> 100baseTX <full-duplex> 100baseTX <full-duplex,hw-loopback> 1000baseTX <full-duplex> 1000baseTX <full-duplex,hw-loopback> 1000baseTX <full-duplex,flow-control> 1000baseTX <full-duplex,flow-control,hw-loopback>
fw0: flags=8822<BROADCAST,SMART,SIMPLEX,MULTICAST> mtu 2030
tunnel inet -->
lladdr 00:30:65:ff:fe:ef:a8:f0
media: autoselect <full-duplex> status: inactive
supported media: autoselect <full-duplex>
ppp0: flags=8051<UP,POINTOPOINT,RUNNING,MULTICAST> mtu 1492
inet 212.212.2.212 --> 212.128.128.12 netmask 0xffffff00


Now I would like to start reading the output from just the last line. Is there anyway to start reading it from the end to the beginning and stop once the inet line is found?

my $ip = $1;
what's $1? Why is that needed?
I suppose it is an internal perl variable like $_, right?

The reason I don't want to use dyndns is, that I don't completely trust it and I might sometimes not need it for more than 30 days which leads to expiration of the address if I read things correctly.

Thanks a lot for your help.

Stephan



Reply via email to