Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- use Net::DNS;
- my $res = Net::DNS::Resolver->new;
- # create the reverse lookup DNS name (note that the octets in the IP address need to be reversed).
- my $IP = "209.85.173.103";
- my $target_IP = join('.', reverse split(/./, $IP)).".in-addr.arpa";
- my $query = $res->query("$target_IP", "PTR");
- if ($query) {
- foreach my $rr ($query->answer) {
- next unless $rr->type eq "PTR";
- print $rr->rdatastr, "n";
- }
- } else {
- warn "query failed: ", $res->errorstring, "n";
- }
- use Socket;
- $iaddr = inet_aton("127.0.0.1"); # or whatever address
- $name = gethostbyaddr($iaddr, AF_INET);
- perl -MSocket -E 'say scalar gethostbyaddr(inet_aton("79.81.152.79"), AF_INET)'
- $ip = "XXX.XXX.XXX.XXX" # IPV4 address.
- my @numbers = split (/./, $ip);
- if (scalar(@numbers) != 4)
- {
- print "$ip is not a valid IP address.n";
- next;
- }
- my $ip_addr = pack("C4", @numbers);
- # First element of the array returned by gethostbyaddr is host name.
- my ($name) = (gethostbyaddr($ip_addr, 2))[0];
Add Comment
Please, Sign In to add comment