>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
>
If you want the ip address of PPPoE connection, change the first line of the script to 
     my $ifconfig = `ifconfig ppp0`;
     
HTH,
Rick Smith

Reply via email to