hornetbzz
hornetbzz

Reputation: 9357

linux bash inet_ntoa inet_aton

I should be blind as I could not find these commands available in the ubuntu and debian's distribution, neither the package containing them.

Shall I code and compile them in C by myself (or write or find this code in perl or whatever language) or is it (I mean inet_aton, inet_ntoa ..) available as a bash command somewhere within these distros ?

Thx

Upvotes: 0

Views: 3350

Answers (2)

BMDan
BMDan

Reputation: 292

At the risk of self-promoting, pure-Bash implementations are available at this Github repo.

Upvotes: 0

Matthew Slattery
Matthew Slattery

Reputation: 46998

inet_ntoa and inet_aton aren't commands - they're library functions, for converting between textual and binary representations of IP addresses.

You can get at these functions easily using the Socket module in Perl:

$ perl -e 'use Socket; print inet_aton("123.45.67.89"), "\n"'
{-CY
$ perl -e 'use Socket; print inet_ntoa("{-CY"), "\n"'
123.45.67.89

or the socket module in Python:

$ python -c 'import socket; print socket.inet_aton("123.45.67.89")'
{-CY
$ python -c 'import socket; print socket.inet_ntoa("{-CY")'
123.45.67.89

but I'm not sure why you'd want to be working with the binary representation of an address in a bash script. (The bytes of the address 123.45.67.89 in the examples above happen to correspond to printable ASCII characters, but you can't expect that to be true in general...)

Upvotes: 3

Related Questions