Support Forums

Full Version: Getting your internal IP with perl, mac and linux
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
As always brought to you by my blog http://bsdpunk.blogspot.com:

For Mac:
PHP Code:
#!/opt/local/bin/perl
my @ifconfig = `ifconfig`;
my $inetter qr/(inet \d+\.\d+\.\d+.\d+)/;
foreach (@
ifconfig) {
my $line $_;
        if (
$line =~ $inetter){
                        print $&.
"\n";
        }

For Linux:

PHP Code:
#!/usr/bin/perl
my @ifconfig = `ifconfig`;
my $inetter qr/(inet addr:\d+\.\d+\.\d+.\d+)/;
foreach (@
ifconfig) {
my $line $_;
        if (
$line =~ $inetter){
                        print $&.
"\n";
        }



If you want this broken down line by line, I do that here:
http://bsdpunk.blogspot.com/2009/07/perl...al-ip.html