前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >linux扫描主机端口

linux扫描主机端口

原创
作者头像
大大刺猬
修改2019-10-18 17:41:56
5.4K0
修改2019-10-18 17:41:56
举报
文章被收录于专栏:大大刺猬

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

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

代码如下:

代码语言:javascript
复制
#!/bin/env bash
#write by ddcw at 30191018
scriptname=$0
function exits(){
  echo -e "\033[31;40m$1\033[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/\033[31;40mscanportDDCW\033[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 "\033[31;40m${host} net unreachable\033[0m"
        exit 1
fi
for i in {1..65536}
do
        if echo &>/dev/null > /dev/tcp/${host}/${i} ;then
                echo -e "${host}:\t\033[31;40m${i}\033[0m  is open"
        fi
done
dtend=`date +%s`
echo -e "this script cost time: \033[32;40m`expr ${dtend} - ${dtbegin}`\033[0m second"

演示:

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档