免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 12298 | 回复: 2
打印 上一主题 下一主题

用shell实现telnet主机端口?? [复制链接]

论坛徽章:
0
1 [报告]
发表于 2006-10-12 10:54 |显示全部楼层
这是我做过的一个小程序,用于测试一些端口是否正常打开,或使用:

#!/bin/bash
#program: Using to study the [if ... then ... fi] program
#Written by: rcui
#date:  2006/08/29
#content: I will using this program to show your services
#1.print the program's work in you screen
        echo "Now,the services of your Linux system will be detect!"
        echo "The www,ftp,ssh,and sendmail + pop3 will be detect!"
        echo ""
#2.www
www='netstat -an | grep LISTEN | grep :80'
if [ "$www" != "" ]; then
        echo "WWW is running"
else
        echo "WWW is NOT running"
fi
#3.ftp
ftp='netstat -an | grep LISTEN | grep :21'
if [ "$ftp" != "" ]; then
        echo "FTP is running"
else
        echo "FTP is NOT running"
fi
#4.ssh
ssh='netstat -an | grep LISTEN | grep :20'
if [ "$ssh" != "" ]; then
        echo "SSH is running"
else
        echo "SSH is NOT running"
fi
#5.sendmail + pop3
smtp='netstat -an | grep LISTEN | grep :25'
pop3='netstat -an | grep LISTEN | grep :110'
if [ "$smtp" != "" ] && [ "$pop3" != "" ]; then
        echo "sendmail is OK!"
elif [ "$smtp" != "" ] && [ "$pop3" = "" ]; then
        echo "sendmail have some problem of your pop3"
elif [ "$smtp" = "" ] && [ "$pop3" != "" ]; then
        echo "sendmail have some problem of your smtp"
else
        echo "sendmail is NOT running"
fi
        echo ""
exit 0

论坛徽章:
0
2 [报告]
发表于 2006-10-12 11:29 |显示全部楼层
你在端口前面加上IP不就行了。如果不知道IP,又不知道怎么去获取。你可以在精华区找一下。

谢谢

论坛徽章:
0
3 [报告]
发表于 2006-10-12 17:06 |显示全部楼层
netstat -an | grep LISTEN | grep 192.168.0.125
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP