convert IP address to integer bash function

#!/bin/bash

ip2long(){
 
 j=0;
 k=0;
 for i in `echo $* | tr '.' '\n' | tac;`
 do
  j="$j+($i*2^$k)"
  k=$(($k+8));
 done;

 echo $j|bc
 
}

ip2long $1
share:

Leave a Reply

Your email address will not be published. Required fields are marked *