Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Server name/IP converter (See related posts)

When passed either an IPv4 address or the name of a domain or server, this script will return either a name or an IP, respectively.
#!/usr/bin/perl -w
use strict;
use Socket;
my $arg = shift;
if ($arg =~ /^(\d+\.){3}\d+$/) {
 print scalar gethostbyaddr(inet_aton($arg), AF_INET), "\n"
} else { printf "%vd\n", scalar gethostbyname $arg }

You need to create an account or log in to post comments to this site.


Click here to browse all 4860 code snippets

Related Posts