CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
gethostbyaddr IPV6

 



ogit2
Novice

Jul 23, 2018, 8:42 AM

Post #1 of 1 (1712 views)
gethostbyaddr IPV6 Can't Post

Hi

I have come across a small challenge and hope someone can help. gethostbyaddr does not resolve IPV6 addresses. I am having to use the function getip which is not ideal as it is very slow. I have also tried to replace 'ping -a' with 'nslookup' to speed things up but 'nslookup' seems to suffer the same problem as the Perl function.

I am using ActivPerl in Windows 2012 server and have also downloaded and installed latest Socket.

If someone has some example code that works or can point me in the right direction, it will be appreciated.


Code
#!C:\Perl\bin\perl.exe 
use Socket;
my $problem = "";
my $addr = "192.168.100.27";
my $name2 = gethostbyaddr(inet_aton($addr), AF_INET) or $problem = "Can't resolve $addr: $!";
my $name = getip($addr);
print "IPV4: GETIP:$name GETHOSTBYADDR:$name2 Error:$problem\n\n";

$problem = "";
$addr = "fe80::4457:6275:1855:1bd4%12";
$name2 = gethostbyaddr(inet_aton($addr), AF_INET) or $problem = "Can't resolve $addr: $!";
$name = getip($addr);
print "IPV6: GETIP:$name GETHOSTBYADDR:$name2 Error:$problem\n\n";

exit;


##################################################################

sub getip
{
my ($ip) = @_;
my $name = "";
my $c10 = chr(10);
my $data = `ping -a $ip 2> nul`;
$data=~ s/$c10/\~/g; #get rid of trailing newlines
$data=~ s/with.*//;
$data=~ s/\[*\]//;
$data=~ s/~Pinging //;
$data=~ s/^\s+//;
$data=~ s/\s+$//;
$name = "$data";
return $name;
}


 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives