大家好,我是Alex。
今天分享一个脚本用来查看连接到端口的ip以及归属地
http://www.kalso.net/archives/461
使用vi checkip.sh
#!/bin/bash
#Purpose: check ip location
ipp (){
exec < $1
while read a
do
sring=`curl -s http://freeapi.ipip.net/${a}| sed 's/\[\|\]\|,\|"//g;s/$/\n/g'`
echo $a $sring
sleep 1
done
}
case $1 in
-f)
shift
ipp $1
;;
-i)
shift
sring=`curl -s http://freeapi.ipip.net/${a}| sed 's/\[\|\]\|,\|"//g;s/$/\n/g'`
echo $1 $sring
;;
*)
echo "[Help]
$0 need -f or -i
-f ------- argument is a file
-i ------- argument is a IP
[For example]:
$0 -f filename
$0 -i ipadress
"
;;
Esac
使用时,bash checkip.sh –f ip.txt用来查询ip.txt文件中的归属地。
再编辑一个ip.sh的脚本来获取端口的连接ip并且调用checkip.sh来查询归属地
vi ip.sh
netstat -tun|grep 443|sort|awk '{print$5}'|cut -d : -f 1|uniq > ip.txt
bash checkip.sh -f ip.txt
如果查询其他端口,改443就可以
修改shell脚本权限,执行下面命令