in reply to How do I get the local internet IP address?
Sometimes, firewalls block a connection setup to a well known IP address. When using the resolve mechanisms it is assumed that the information — e.g. in /etc/hosts, name servers, etc. — is maintained, accessible, trusted, and valid.
If both methods fail, a look at the actual IP configuration might help. As a (okay, maybe not the very) last resort, esp. when multiple interfaces and IPMP is concerned, examining the output of
/sbin/ifconfig -a (*NIX), or
ipconfig /all (WIN*) might
work to reveal the interfaces currently plumbed and configured.
At least the OS's tool which is responsible to configure the IPs should be able to give a reliable answer.
The fragile part is to rely on the outputs layout.
You might need to change the locale language (e.g. LANG, LC_ALL) beforehand.
#!/usr/bin/perl use strict; use Data::Dumper; my $interface; my %IPs; foreach ( qx{ (LC_ALL=C /sbin/ifconfig -a 2>&1) } ) { $interface = $1 if /^(\S+?):?\s/; next unless defined $interface; $IPs{$interface}->{STATE}=uc($1) if /\b(up|down)\b/i; $IPs{$interface}->{IP}=$1 if /inet\D+(\d+\.\d+\.\d+\.\d+)/i; } print Dumper(\%IPs); __END__ $VAR1 = { 'qfe0' => { 'IP' => '10.0.0.32', 'STATE' => 'UP' }, 'qfe1' => { 'IP' => '10.0.0.33', 'STATE' => 'UP' }, 'hme0' => { 'IP' => '10.0.0.14', 'STATE' => 'DOWN' }, 'lo0' => { 'IP' => '127.0.0.1', 'STATE' => 'UP' } };
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Answer: How do I get the local internet IP address?
by jasonk (Parson) on Aug 14, 2008 at 01:06 UTC | |
by Your Mother (Archbishop) on Aug 14, 2008 at 06:53 UTC | |
Re: Answer: How do I get the local internet IP address?
by betterworld (Curate) on Aug 14, 2008 at 14:31 UTC | |
Re: Answer: How do I get the local internet IP address?
by Perlbotics (Archbishop) on Aug 14, 2008 at 21:15 UTC |