IP Address Converter

后端 未结 7 1068
臣服心动
臣服心动 2020-12-29 11:17

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

7条回答
  •  离开以前
    2020-12-29 11:52

    Here's my take:

    $ host google.com
    google.com has address 216.58.216.142
    $ ./ip2d.sh 216.58.216.142
    3627735182
    $ ./d2ip.sh 3627735182
    216.58.216.142
    

    ip2d.sh:

    #!/bin/bash
    
    IFS=.
    set -- $*
    echo $(( ($1*256**3) + ($2*256**2) + ($3*256) + ($4) ))
    

    d2ip.sh:

    #!/bin/bash
    
    IFS=" " read -r a b c d  <<< $(echo  "obase=256 ; $1" |bc)
    echo ${a#0}.${b#0}.${c#0}.${d#0}
    

提交回复
热议问题