Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: Extracting network information

by stevieb (Canon)
on Sep 01, 2015 at 17:29 UTC ( [id://1140701]=note: print w/replies, xml ) Need Help??


in reply to Extracting network information

I don't have time to try any modules right now (which I'd search out instead of shelling out), but here's a way with less external calls:

#!/usr/bin/perl use warnings; use strict; my $hostname = `hostname`; my $config = `ifconfig`; $config =~ m/ inet\saddr: (\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}) .*? Mask: (\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}) /x; if ($1 && $2 && $1 !~ /127\.0\.0/){ my $ip = $1; my $netmask = $2; print "hostname: $hostname" . "IP: $ip\n" . "Netmask: $netmask\n"; } __END__ hostname: steve-ws IP: 10.0.48.1 Netmask: 255.255.255.0

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1140701]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (3)
As of 2024-04-25 20:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found