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

Re: Read network configuration on FreeBSD

by VinsWorldcom (Vicar)
on Oct 10, 2012 at 17:09 UTC ( #998265=note: print w/ replies, xml ) Need Help??


in reply to Read network configuration on FreeBSD

Seplling? That says 'addrese', I assume it should be 'address'?

And if you're using the synopsis directly from the POD for IO::Interface, you probably shouldn't mix the new and old API.


Comment on Re: Read network configuration on FreeBSD
Replies are listed 'Best First'.
Re^2: Read network configuration on FreeBSD
by josef (Acolyte) on Oct 10, 2012 at 17:24 UTC
    Ups, I correct the line with 'addrese' to 'address' but the error still remain :
    Can't locate object method "address" via package "re0" (perhaps you fo +rgot to load "re0"?) at interfaces.pl line 25.
Re^2: Read network configuration on FreeBSD
by josef (Acolyte) on Oct 10, 2012 at 17:41 UTC
    My script is now:
    #! /usr/bin/perl -w use Data::Dumper::Simple; use IO::Interface::Simple; my @interfaces = IO::Interface::Simple->interfaces; #print Dumper @interfaces; for my $if (@interfaces) { next if $if =~ /usb|iwn|lo/; print "interface = " . $if . "\n"; print "addr = " . $if->address . "\n"; print "broadcast = " . $if->broadcast ."\n"; print "netmask = " . $if->netmask ."\n"; print "dstaddr = " . $if->dstaddr . "\n"; # line 15 print "hwaddr = " . $if->hwaddr . "\n"; # line 16 print "mtu = " . $if->mtu . "\n"; print "metric = " . $if->metric . "\n"; print "index = " . $if->index . "\n"; print "is running\n" if $if->is_running; print "is broadcast\n" if $if->is_broadcast; print "is p-to-p\n" if $if->is_pt2pt; print "is loopback\n" if $if->is_loopback; print "is promiscuous\n" if $if->is_promiscuous; print "is multicast\n" if $if->is_multicast; print "is notrailers\n" if $if->is_notrailers; print "is noarp\n" if $if->is_noarp; } and the result is like: interface = re0 addr = 172.21.100.29 broadcast = 172.21.100.255 netmask = 255.255.255.0 Use of uninitialized value in concatenation (.) or string at int.pl li +ne 15 dstaddr = hwaddr = c8:0a:a9:93:87:25 mtu = 1500 metric = 0 index = 6 is running is broadcast is multicast Your vendor has not defined IO::Interface macro IFF_NOTRAILERS at /usr +/local/lib/perl5/site_perl/5.14.2/mach/IO/Interface/Simple.pm line 11 +7

      Just check if the values are defined before printing them. I don't have a linux system so I don't know why IO::Interface (which does't compile for me on Windows/Strawberry) doesn't return a dstaddr or hwaddr.

      printf "dstaddr = %s\n", defined($if->dstaddr) ? $if->dstaddr : ''; +# line 15 printf "hwaddr = %s\n", defined($if->hwaddr) ? $if->hwaddr : ''; # +line 16
      Hmm, the script read now the interface parameters but not for the IP addresses as alias.

      I will be very happy to get the media and the speed of the interface:

      media: Ethernet autoselect (100baseTX <full-duplex>)

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (13)
As of 2015-07-28 09:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (254 votes), past polls