[Snort-users] how to convert sql ipsrc hdrs to quad notation

Brian bmc at ...950...
Fri Oct 12 14:23:06 EDT 2001

According to Frontgate Lab:
> Hi,
>  does anyone have a script that converts these to dotted quad notation? 
> can you at least guide me in the direction of writting such a script? ie
> the math behind it < where do i find it?

If you wanted to do this in perl...

To convert to an int:
my $ddip = $ARGV[0];
my @bytelist = split /\./, $ddip;
my $packedip = $bytelist[3] +
($bytelist[2]*256) +
($bytelist[1]*65536) +
print "$packedip\n";

To convert from an int:
use Socket;
if (@ARGV) { $ip = $ARGV[0]; } else {$ip = <STDIN>; }
$ip = inet_ntoa(pack("V", $ip));
$ip =~ s/(\d+).(\d+).(\d+).(\d+)/$4.$3.$2.$1/g;
print "$ip\n";


More information about the Snort-users mailing list