Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much

DNS Lookup

by jaldama (Acolyte)
on Jan 19, 2012 at 19:28 UTC ( #948837=perlquestion: print w/ replies, xml ) Need Help??
jaldama has asked for the wisdom of the Perl Monks concerning the following question:

Howdy! I've spent some time reading about looking up a DNS in perl but am having trouble with my script. Hoping someone could give me a hint as to where I've gone wrong?

#!/usr/bin/perl-w use Socket; if ( $#ARGV != 0 ) { print "Usage: $0 hostname\n"; exit(1); } $userinput = $ARGV[0]; if ($userinput =~ m/^(\d+)\.(\d+)\.(\d+)\.(\d+)$/ ) { $userinput = $ip; $hostname = gethostbyaddr(inet_aton($ip), AF_INET) or die "Can't R +esolve $ip: $!\n"; print $hostname; } else { $userinput = $name; $ipaddr = gethostbyname($name) or die "Can't resolve $name: $!\n"; $ipaddr = inet_ntoa(inet_aton($name)); print $ipaddr; } ##prints this? $ perl Can't resolve : No such file or directory

Comment on DNS Lookup
Download Code
Re: DNS Lookup
by toolic (Chancellor) on Jan 19, 2012 at 19:34 UTC
    $userinput = $name;
    $name = $userinput;

    I think you were missing the warning that I see because your shebang line is messed up (add a space before the -w), and you are probably bypassing it anyway by invoking your script with the perl executable on the command line. Also add:

    use warnings;
    use strict and warnings

    The same goes for $userinput = $ip;

      Ahh, life makes sense again.

        Yes, for the most part :)

Re: DNS Lookup
by Khen1950fx (Canon) on Jan 20, 2012 at 10:09 UTC





Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://948837]
Approved by marto
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (4)
As of 2014-12-27 14:28 GMT
Find Nodes?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?

    Results (177 votes), past polls