/ Published in: Perl
This method doesn't rely on parsing 'ifconfig' tool output, and should work in any Linux distribution, but also could work in other POSIX environments. The function returns a string with IPv4 address or 'undef' if it's not possible.
Expand |
Embed | Plain Text
#!/usr/bin/perl use strict; use warnings; use Socket; require 'sys/ioctl.ph'; sub get_interface_address { my ($iface) = @_; my $socket; socket($socket, PF_INET, SOCK_STREAM, (getprotobyname('tcp'))[2]) || die "unable to create a socket: $!\n"; { } }
You need to login to post a comment.
