LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous messageNext messagePrevious in topicNext in topicPrevious by same authorNext by same authorPrevious page (October 2001, week 3)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Tue, 16 Oct 2001 22:07:42 -0000
Reply-To:     David Wall <darkon@ONE.NET>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         David Wall <darkon@ONE.NET>
Organization: Posted via Supernews, http://www.supernews.com
Subject:      Re: Resolving an IP-address

I wrote: > Since all you want to do is turn IPs > into DNS, write one simple (non-SAS) program that reads an input > (text) file with IP addresses, one per line, resolves the DNS name, > and creates an output file with the IP address and DNS name on the > same line. Then have SAS get the IPs, write them to a text file, use > x to execute the little non-SAS program, then have SAS read in the IP > and DNS from the output file. I'd write the non-SAS part in Perl, > since it has tools that make this kind of thing easy, but you could > use C or whatever.

Here's a short Perl program to do what I said above:

#!/usr/bin/perl use strict; use warnings; use Socket;

my $in = 'ip-addresses'; # input: file containing IPs, one per line my $out = 'ip-dns'; # output: ip and dns name

open IN, "$in" or die "Error opening $in: $!"; open OUT, ">$out" or die "Error opening $out: $!"; while (<IN>) { chomp; my $ip = inet_aton $_; my $dns = gethostbyaddr $ip, AF_INET; print OUT "$_ $dns\n"; }

Note that this will not necessarily get you the hostname you expect. I pinged www.yahoo.com to get an IP address for testing, but when I used that IP to get a hostname, I got back w5.dcx.yahoo.com.

-- David Wall darkon@one.net


Back to: Top of message | Previous page | Main SAS-L page