Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!know!zaphod.mps.ohio-state.edu!uakari.primate.wisc.edu!aplcen!haven!umd5!sherk From: sherk@umd5.umd.edu (Erik Sherk) Newsgroups: comp.lang.perl Subject: DNS lookup within perl Summary: How do I do a nslookup from perl Keywords: nslookup Message-ID: <7028@umd5.umd.edu> Date: 2 Aug 90 21:09:26 GMT References: <1593@kuling.UUCP> Reply-To: sherk@nmc.cit.cornell.edu (Erik Sherk) Organization: Cornell University, Ithaca, NY Lines: 30 Hello, I need to find the name of a host from within a perl script. The following seems to work, but there must be a better way! ---------------- ($1, $2, $3, $4) = split(/\./, $IPaddr); $query = sprintf("set querytype=ptr\n%d.%d.%d.%d.in-addr.arpa", $4,$3,$2,$1); $nsreply = `echo '$query' | nslookup 2>/dev/null | \ egrep 'in-addr'|egrep -v 'domain'`; ($foo, $foo, $foo, $foo, $host) = split( /[ \t\n]+/, $nsreply ); ---------------- (I split the third line for readability) You will note that this takes four processes to do what one system call should do! Also, there is the need to redirect stderr from nslookup. Is there any way to "split" a string without specifing the field separators? Please help, this is my first perl script! Erik Sherk sherk@nmc.cit.cornell.edu P.S. please email direct, as I am 85 articles behind in comp.lang.perl