如何更改eve telenet注册表 更改默认程序序

Code a simple telnet client using sockets in python
The telnet client is a simple commandline utility that is used to connect to socket servers and exchange text messages. Here is an example of how to use telnet to connect
and fetch the homepage.
The above command will connect
on port 80.
Trying 74.125.236.69...
Connected .
Escape character is '^]'.
Now that it is connected, the telnet command can take user input and send to the server, and whatever the server replies with, will be displayed on the terminal. For example send the http GET command and hit enter twice.
GET / HTTP/1.1
Sending the above will generate some response from the server. Now we are going to make a similar telnet program in python. The program is short and simple. To implement a program that takes user input and fetches results from the remote server at the same, requires somekind of parallel processing. Now the obvious solution to this is to use threads. One thread to keep receiving message from server and another to keep taking in user input. But there is another way to do this apart from threads. And that is select function. Select function allows to monitor multiple sockets/streams for readability and will generate an even if any of the sockets is ready.
Lets take a look at the full code. Its less than 50 lines including comments.
# telnet program example
import socket, select, string, sys
#main function
if __name__ == &__main__&:
if(len(sys.argv) & 3) :
print 'Usage : python telnet.py hostname port'
sys.exit()
host = sys.argv[1]
port = int(sys.argv[2])
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.settimeout(2)
# connect to remote host
s.connect((host, port))
print 'Unable to connect'
sys.exit()
print 'Connected to remote host'
socket_list = [sys.stdin, s]
# Get the list sockets which are readable
read_sockets, write_sockets, error_sockets = select.select(socket_list , [], [])
for sock in read_sockets:
#incoming message from remote server
if sock == s:
data = sock.recv(4096)
if not data :
print 'Connection closed'
sys.exit()
#print data
sys.stdout.write(data)
#user entered a message
msg = sys.stdin.readline()
s.send(msg)
Small program! Just run it in a terminal like this
$ python telnet. 80
Connected to remote host
Once connected it shows the connected message. Once the message pops up, its time to type in some message to send to the remote server. Type the same GET message and send by hitting enter twice. Some response should be generated.
The above program does the task of listening for message from remote server and listening for user input at the same time, and without threads.
socket_list = [sys.stdin, s]
# Get the list sockets which are readable
read_sockets, write_sockets, error_sockets = select.select(socket_list , [], [])
The socket list contains 2 sockets. First is the sys.stdin which is stream for standard input or the user input at the command line. The other one is the socket that is connected to remote server. The select function keeps listening on both of them. It is a blocking function and returns if either of the 2 things happens
1. Server sends a message
2. User hits enter after typing in a message
If the server socket is ready to be read, then just call recv function on it. If the user input is ready to be read then call sys.stdin.readline() function get the user message. Thats all about it.
The telnet client shown above is a minimal one. The actual telnet client has lots of other features which you can try to implement. The above telnet client can be used as a terminal chat client as well with little modifications. Just have to write a chat server. Will come up with a post on that soon.
The above shown program will work only on linux and not on windows. The program uses the select function read the command line input (stdin). On windows the select function cannot read file descriptors. It can only read sockets created inside winsock. The python documentation on
function mentions this
File objects on Windows are not acceptable, but sockets are. On Windows, the underlying select() function is provided by the WinSock library, and does not handle file descriptors that don&t originate from WinSock.
Subscribe to get updates delivered to your inbox
Related Posts
About Silver Moon
Php developer, blogger and Linux enthusiast.
He can be reached at .
Or find him on
I want to test a list with sockets how can I use it?
Connect with us
Other interesting stuff
Copyright & 2017 BinaryTides如何检测服务器网络端口是否打开--详细图文教程
本文介绍如何检测本机网络是否支持某些端口,这在排除VPN连接失败原因时还是有一定帮助的,比如像有些公司、网吧等公共网络会限制VPN协议相关端口,从而无法连接使用。如果单纯针对电脑限制的还相对好办,可以使用之前我们介绍的一个解除限制批处理。另外也可以参考连接错误代码查找问题原因。
下文检测端口使用的是telnet命令,只支持TCP端口检测。如果需要批量扫描检测,显然手动敲CMD是不太现实的,可以使用Nmap和X-scan等专业软件。
XP系统可以直接运行telnet命令,Visat以上系统则默认不支持telnet命令使用,需要添加组件支持,方法如下:依次打开“控制面板”——“程序和功能”——点击左侧的“打开或关闭Windows功能”——在组件添加窗口中勾选“Telnet客户端”,如下图,确定安装后就可以使用了。另外Linux系统命令使用也差不多,这里就不做介绍了。
TELNET命令使用方法:
同时按下Win+R组合键(Win键就是键盘上微软标志那个按键),在弹出运行窗口中输入CMD,点击确定。然后在命令行窗口输入以下类似命令检测。
telnet 127.0.0.1 1723
解释一下上面命令含义:
telnet:发出一个telnet命令检测
127.0.0.1:检测服务器地址(本机的话是127.0.0.1,也可以直接填写VPN服务器地址检测)
1723:检测端口(PPTP协议TCP端口为1723,L2TP协议UDP端口为1701,OPENVPN协议UDP/TCP默认端口为1194。注意,telnet命令不支持UDP端口检测,另外OPENVPN使用端口是支持自定义的,所以各家VPN服务商使用端口也可能不一样)
下面图文示例一下检测方法:
输入命令回车执行后,如果没有报错,默认显示空白,则说明端口已打开。
如果显示报错连接失败,则表示检测端口关闭。
TELNET命令大全:
telnet [-d] [-a] [-n tracefile] [-e escapechar] [[-l user] host
其中各项的含义如下:
-d 设置调试开关的初始值为TRUE
-a 尝试自动登录。就目前而言,这个选项用于通过ENVIRON 选项的USER变量发送用户名(如果远程主机支持这种用法的话)。如果函数
getlogin(2)返回的当前用户所用的名字与当前用户ID相一致,那么USER变量就为该命令返回的名字,否则为与当前用户ID对应的用户名。
-n tracefile打开tracefile文件以记录跟踪信息。
-l user当连接至远程系统时,如果远程主机支持ENVIRON
选项,则当前用户名将作为变量USER的值发送至远程主机。本选项自动包括-a选项。
-e escapechar把TELNET转义字符的初始值设置为escapechar。如果忽略本选项,则无转义字符。
host表示远程主机的正式名称、别名或IP地址。
port端口号,即各种Internet应用程序地址。如未指明端口号,则使用telnet的缺省端口号。
如果telnet命令不带任何参数,则系统将进入telnet命令状态,其提示符是telnet&。在提示符后可以使用各种telnet命令。比方说,在提示符后键入help命令,可以得到telnet命令表。telnet命令及其功能描述见下。
命令功能描述:
close关闭当前连接
logout强制退出远程用户并关闭连接
display显示当前操作的参数
mode试图进入命令行方式或字符方式
open连接到某一站点
telnetsend发送特殊字符
set设置当前操作的参数
unset复位当前操作参数
status打印状态信息
toggle对操作参数进行开关转换
slc改变特殊字符的状态
auth打开/关闭确认功能z挂起
telnetenviron更改环境变量?显示帮助信息
这些命令均可采用缩写形式,只要相互之间不会产生冲突。telnet命令一般都直接后跟节点名,表示将注册到指定的远方机器。例如命令:telnet
ox6.。登录到远程主机后,就可以开始使用该机器上的资源及其所能提供的服务,甚至可以再次登录到其它主机。
注释:可能你已经注意到,“远程登录”中的“远程”只是一个逻辑上的概念。也就是说,你通过远程登录方式登录到的主机也许远在天涯,也许近在咫尺。
如果远程节点使用的telnet端口号不是标准TCP端口
(telnet的标准端口为23),那么还需要在主机名后面附上相应的端口号。如下面的命令:telnet
eve.assumption.edu 5000
注释:端口指的是远程机器上某个特定应用程序的位置。如果登录到远程主机时没有指定端口,那么它将认为你是一个固定用户,并希望你在进入系统之前输入有效的用户名和口令。当通过特定端口连接时,主机并不要求输入用户名,但是限制用户使用一种特殊的功能。
退出:一旦登录到某个远程主机,你就成了该计算机的一个用户。我们知道,Internet上各台主机的硬件环境、操作系统和
应用程序存在很大的异构性。因此,其退出方式也不尽相同。不过,就一般情形而言,你可以依次尝试使用
q,quit,exit,logout,Ctrl+D或done等命令,也许其中某个命令可以帮助你结束本次操作,使你返回到UNIX提示状态下。如果尝
试未告成功,不妨试用Ctrl+]返回到telnet&
提示下,然后键入close或quit并按Enter键。比方说,如果你已经从bjlad.主机远程登录到
ox6.主机,现在希望回到本地机器,则可以输入exit命令,或用Ctrl+]返回到telnet&提示。这里假定你用
Ctrl+]结束telnet连接。然后再输入quit命令,以希望回到 bjlad.
主机的UNIX提示符下。这时的屏幕显示为:
telnet&quit
Connection closed.
已投稿到:
以上网友发言只代表其个人观点,不代表新浪网的观点或立场。安全检查中...
请打开浏览器的javascript,然后刷新浏览器
< 浏览器安全检查中...
还剩 5 秒&

我要回帖

更多关于 mac更改默认打开程序 的文章

 

随机推荐