/ 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.
The function returns a string with IPv4 address or 'undef' if it's not possible.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
#!/usr/bin/perl use strict; use warnings; use Socket; sub get_interface_address { my ($iface) = @_; my $socket; socket($socket, PF_INET, SOCK_STREAM, (getprotobyname('tcp'))[2]) || die "unable to create a socket: $!\n"; { } }
Comments
