linux扫描主机端口

2019-10-18 17:41:56 浏览数 (1)

使用方法:在linux环境下执行如下shell脚本,即可在/usr/bin下面生成脚本scanportDDCW.

scanportDDCW使用说明:直接执行该脚本显示本机开发的端口,scanportDDCW 主机 扫描主机开发的端口

代码如下:

代码语言:javascript复制
#!/bin/env bash
#write by ddcw at 30191018
scriptname=$0
function exits(){
  echo -e "33[31;40m$133[0m"
  exit 0
}
[ "`whoami`" == "root" ] || exits "this script must run by ROOT , n(tips:tail -n  16 ${scriptname} )"
function set_SCANPORT() {
        [ -f /usr/bin/scanportDDCW ]  && exits "this os maybe have /usr/bin/scanportDDCW  ,(so ,this script will be exit...)"
        touch /usr/bin/scanportDDCW && tail -n  16 ${scriptname} > /usr/bin/scanportDDCW
        chmod 755 /usr/bin/scanportDDCW && echo -e "now,you can run  /usr/bin/33[31;40mscanportDDCW33[0m [hostname or ip]  to get port of hosts,tips:default hostname is this OS `hostname`"
}
set_SCANPORT
exit 0
#!/bin/env bash
#write by ddcw at 30190823
dtbegin=`date  %s`
host=$1
[ -z ${host} ] && host=`hostname`
if ping -c 1 ${host} >/dev/null ;then
        echo -e "${host} has been scann.........."
else
        echo -e "33[31;40m${host} net unreachable33[0m"
        exit 1
fi
for i in {1..65536}
do
        if echo &>/dev/null > /dev/tcp/${host}/${i} ;then
                echo -e "${host}:t33[31;40m${i}33[0m  is open"
        fi
done
dtend=`date  %s`
echo -e "this script cost time: 33[32;40m`expr ${dtend} - ${dtbegin}`33[0m second"

演示:

0 人点赞