Support Forums
Getting your internal IP with perl, mac and linux - Printable Version

+- Support Forums (https://www.supportforums.net)
+-- Forum: Categories (https://www.supportforums.net/forumdisplay.php?fid=87)
+--- Forum: Coding Support Forums (https://www.supportforums.net/forumdisplay.php?fid=18)
+---- Forum: Perl Programming Support (https://www.supportforums.net/forumdisplay.php?fid=31)
+---- Thread: Getting your internal IP with perl, mac and linux (/showthread.php?tid=1950)



Getting your internal IP with perl, mac and linux - bsdpunk - 10-21-2009

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-tutorial-on-getting-internal-ip.html