Chinaunix

标题: 用shell实现telnet主机端口?? [打印本页]

作者: zhongf1114    时间: 2006-10-10 10:07
标题: 用shell实现telnet主机端口??
请教高手,如何用shell实现telnet对端端口啊?并且返回结果?
作者: mcknight    时间: 2006-10-10 18:12
请教高手,如何用shell实现telnet对端端口啊?并且返回结果?


楼主什么意思啊?
作者: sunkez    时间: 2006-10-10 22:44
是不是说的是用超级服务做代理的呢
作者: zhongf1114    时间: 2006-10-12 10:51
标题: 回复 2楼 mcknight 的帖子
目的就是为了测试对端端口有没开通服务
作者: cyaln    时间: 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
作者: zhongf1114    时间: 2006-10-12 11:28
谢谢,你的是测试本机的,我要的是测试远程主机的端口。
作者: cyaln    时间: 2006-10-12 11:29
你在端口前面加上IP不就行了。如果不知道IP,又不知道怎么去获取。你可以在精华区找一下。

谢谢
作者: zhongf1114    时间: 2006-10-12 12:14
netstat -an | grep LISTEN | grep :192.168.0.1 25
是这样吗?好象不行
作者: waker    时间: 2006-10-12 12:18
能不能问个问题:你想问什么?
作者: zhongf1114    时间: 2006-10-12 12:21
标题: 回复 9楼 waker 的帖子
我有台服务器发数据包给另外一台主机,假设他给我开的端口是1234
现在我要用一个shell测试下它这个端口1234服务是不是起来了?
作者: waker    时间: 2006-10-12 12:31
如果有nmap

nmap 另外一台主机 -p1234
作者: freecoder    时间: 2006-10-12 15:37
telnet IP Port 就可以知道端口开没开啊
作者: cyaln    时间: 2006-10-12 17:06
netstat -an | grep LISTEN | grep 192.168.0.125
作者: twf_cc    时间: 2006-10-16 22:18
nc -vv -z remote_host port
ex
[victor@localhost ~]$ nc -vv -z 137.189.91.191 21
Connection to 137.189.91.191 21 port [tcp/ftp] succeeded!
[victor@localhost ~]$

[ 本帖最后由 twf_cc 于 2006-10-16 23:03 编辑 ]
作者: vantien    时间: 2006-10-16 23:11
原帖由 twf_cc 于 2006-10-16 22:18 发表
nc -vv -z remote_host port
ex
[victor@localhost ~]$ nc -vv -z 137.189.91.191 21
Connection to 137.189.91.191 21 port [tcp/ftp] succeeded!
[victor@localhost ~]$


这招好用哦
速度又快
学起来 ^^

[ 本帖最后由 vantien 于 2006-10-16 23:13 编辑 ]
作者: skw    时间: 2006-10-19 16:46
你可以用“telnet <对端主机IP> 1234”来测试呀
作者: feixiang2966    时间: 2006-10-19 19:04
标题: 回复 1楼 zhongf1114 的帖子
telnet xxx.xxx.xxx.xxx 1234
作者: twf_cc    时间: 2006-10-22 18:15
原帖由 vantien 于 2006-10-16 23:11 发表


这招好用哦
速度又快
学起来 ^^


見笑,
大量的 port scrn , nc 相當不錯

[victor@localhost ~]$ nc -vv -z 137.189.91.191 11-30
nc: connect to 137.189.91.191 port 11 (tcp) failed: Connection refused
nc: connect to 137.189.91.191 port 12 (tcp) failed: Connection refused
nc: connect to 137.189.91.191 port 13 (tcp) failed: Connection refused
nc: connect to 137.189.91.191 port 14 (tcp) failed: Connection refused
nc: connect to 137.189.91.191 port 15 (tcp) failed: Connection refused
nc: connect to 137.189.91.191 port 16 (tcp) failed: Connection refused
nc: connect to 137.189.91.191 port 17 (tcp) failed: Connection refused
nc: connect to 137.189.91.191 port 18 (tcp) failed: Connection refused
nc: connect to 137.189.91.191 port 19 (tcp) failed: Connection refused
nc: connect to 137.189.91.191 port 20 (tcp) failed: Connection refused
Connection to 137.189.91.191 21 port [tcp/ftp] succeeded!
nc: connect to 137.189.91.191 port 22 (tcp) failed: Connection refused
nc: connect to 137.189.91.191 port 23 (tcp) failed: Connection refused
nc: connect to 137.189.91.191 port 24 (tcp) failed: Connection refused
nc: connect to 137.189.91.191 port 25 (tcp) failed: Connection refused
nc: connect to 137.189.91.191 port 26 (tcp) failed: Connection refused
nc: connect to 137.189.91.191 port 27 (tcp) failed: Connection refused
nc: connect to 137.189.91.191 port 28 (tcp) failed: Connection refused
nc: connect to 137.189.91.191 port 29 (tcp) failed: Connection refused
nc: connect to 137.189.91.191 port 30 (tcp) failed: Connection refused
[victor@localhost ~]$
作者: langue    时间: 2006-10-22 18:28
原帖由 twf_cc 于 2006-10-22 18:15 发表


見笑,
大量的 port scrn , nc 相當不錯

[victor@localhost ~]$ nc -vv -z 137.189.91.191 11-30
nc: connect to 137.189.91.191 port 11 (tcp) failed: Connection refused
nc: connect to 137.18 ...


这个是端口扫描……
作者: 少林功夫好    时间: 2014-07-24 10:20
回复 14# twf_cc


    确实很简单啊。此方法收下了。谢谢。
另外我猜楼主的意思应该是,telnet命令如何在shell脚本里判断端口是否能连通。




欢迎光临 Chinaunix (http://bbs.chinaunix.net/) Powered by Discuz! X3.2