[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [MacPerl] TCP/IP address



>I have a script that wants to run over a dialup PPP connection. The script
>needs to know the TCP address of the mac on which it is running, but that 
>address is dynamic, being set at connect time. How can one find that 
>information from within macperl?

Hey, Jason,

There's likely a better way to do this, but something sleazy like this 
works:

=-=-=-=-=
#!perl

use Sys::Hostname;

($name,$aliases,$addrtype,$length,@addrs) = gethostbyname(&hostname);

($a,$b,$c,$d) = unpack('C4',$addrs[0]);

$ipaddr = "$a.$b.$c.$d";

print $ipaddr."\n";
=-=-=-=-=

More likely than not, your script would let you use $addrs[0] in its 
un-unpacked state.  (I'm assuming that you really only need the IP 
address and not info about a specific TCP socket).

Good luck,

-Charles
 charlesa@aol.net
 AOL Productions South