1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
use strict;
use warnings;
use File::Copy;
use File::stat;
use Proc::Daemon;
use Proc::ProcessTable;
use Errno qw(:POSIX);
use List::Util qw[min max];
use Net::Netmask;
use Config::IniFiles;
use IO::Interface::Simple;
use JSON;
use utf8;
# Proc::Daemon::Init;
my $habriconfig = "/opt/habridge/data/habridge.config";
sub correctHiBridgeIP();
sub correctHiBridgeIP()
{
if ( -e $habriconfig )
{
my %addresses = map
{
($_ => [map { Net::Interface::inet_ntoa($_) } $_->address]);
} Net::Interface->interfaces;
print "testtesttest";
foreach (%addresses)
{
print "Test: $_\n";
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#!/usr/bin/perl
use strict;
use warnings;
use Socket;
require 'sys/ioctl.ph';
print get_interface_address('eth0');
sub get_interface_address
{
my ($iface) = @_;
my $socket;
socket($socket, PF_INET, SOCK_STREAM, (getprotobyname('tcp'))[2]) || die "unable to create a socket: $!\n";
my $buf = pack('a256', $iface);
if (ioctl($socket, SIOCGIFADDR(), $buf) && (my @address = unpack('x20 C4', $buf)))
{
return join('.', @address);
}
return undef;
}
QuoteCan't locate object method "interfaces" via package "Net::Interface"
@all_ifs = Net::Interface->interfaces();