Ip addresses: Converting from long form to dotted form in a shell script

Jul 04, 2005 3 Replies

In article , jzz wrote: :How do you convert long form ip addresses retreived from a database :into a dotted form ip address?

What do you mean by a "long form ip address" ? Do you mean an IPv6 address? Or do you mean a hostname?

If you mean a hostname, then the internal mechanism would normally be to place a call to gethostbyname() or equivilent.

To do the same in a shell script, you would need to find your system's host name resolution facilities and use that. That might be through a command such as 'nslookup', or might be through 'dig', or might be through something completely different yet considering that you didn't mention which shell you were using or which operating system.

(No, hostname resolution is NOT a standard shell facility. And it isn't a standard firewall facility either, so comp.security.firewalls would not appear to be an appropriate newsgroup .)

Not exactly sure what you mean but are you talking about "shrouded URLs"? Check out this free utility... maybe it's what you want.

formatting link

I'll throw in a suggestion here aswell, in case its dword adresses you got in your database:

$dword = 2130706433;

$octet1 = int($dword / 16777216); $dword %= 16777216;

$octet2 = int($dword / 65536); $dword %= 65536;

$octet3 = int($dword / 256); $dword %= 256;

$octet4 = $dword;

$address = "$octet1.$octet2.$octet3.$octet4";

# $address now contains "127.0.0.1"

(it's perl, but should be pretty easy to read regardless of what language you're familiar with)

Join the Discussion

Have something to add? Share your thoughts — no account required.

Didn't find your answer?

Ask the community — no account required