Greetings,

I need to convert the first column of a list of IP numbers to IP addresses. I created an array of my list but am stumped on how to convert the numbers.

File:
180884576       imstrmcs05
180884577       imstrmcs06
180884578       imstrmcs07
180884579       imstrmcs08
180884580       imstrmcs09
180884581       imstrmcs10


Script:
# Properly formatting into an array
open(IPLIST, "file") || die "couldn't open the file";

while ($x = <IPLIST>)
{
chop $x;
@arr = split /\s+/,$x;
print "@arr\n";
}

# Converting IP number to IP address.
foreach $ipaddr {
$ip1 = int ($ipaddr / (256**3));
$ipaddr %= ($ip1 * 256**3);
$ip2 = int ($ipaddr / (256**2));
$ipaddr %= ($ip2 * 256**2);
$ip3 = int ($ipaddr /256);
$ip4 = $ipaddr % ($ip3 * 256);

$realip=$ip1 . "." . $ip2 . "." . $ip3 . "." . $ip4;
print "$realip\n";
}

close(IPLIST);


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to