There is IP address: 66.102.13.19, and from this address as that received this address
http://1113984275
But how? And how I can make this with the help of bash. For example, this service can do it, but I do not understand the algorithm.
There is IP address: 66.102.13.19, and from this address as that received this address
http://1113984275
But how? And how I can make this with the help of bash. For example, this service can do it, but I do not understand the algorithm.
Binary shifting is always faster than multiplying or dividing.
Using a binary AND is faster than mod.
Note: This system will fail with values like
0008
.Bash thinks it is an octal number.
To solve that, each value will have to be cleaned with something like:
For (very) old shells: bash since 2.04, or dash or any (reasonable) shell:
my version for int to ip conversion:
echo 3232235521| awk {'print rshift(and($1, 0xFF000000), 24) "." rshift(and($1, 0x00FF0000), 16) "." rshift(and($1, 0x0000FF00), 8) "." and($1, 0x000000FF) '}
Simple int to IP conversion for bash
Here's my take:
ip2d.sh:
d2ip.sh:
By the way, the number in your question doesn't match the IP address.
To convert a decimal to an IP:
To convert an IP to a decimal:
Demo:
These two scripts rely on features of Bash that aren't present in some Bourne-derived shells. Here are AWK versions to use instead:
and
They can be called in the same manner as the Bash scripts above.
I think there's a simpler solution that also handles an arbitrary number of octets with no references to fixed offsets etc.
output: 1113984275