主页 > 焦点科技 >张婉悠厕所门完整版_在cmd命令下,怎样查看serverSocket所监听的端口有没有存在 >

张婉悠厕所门完整版_在cmd命令下,怎样查看serverSocket所监听的端口有没有存在

在cmd命令下,怎样查看serverSocket所监听的端口有没有存在?
使用netstat命令
我一般用的netstat -ano
-a表示列出所有(all)
-n表示列出的是IP地址,而不是主机名
-o表示显示PID以从进程中查看对应的进程占用了什么端口。。。

我附上netstat的所有命令行:
06/01/2011 Wed13:05:52.74 >>netstat /?
Displays protocol statistics and current TCP/IP network connections.
NETSTAT [-a] [-b] [-e] [-n] [-o] [-p proto] [-r] [-s] [-v] [interval]
-aDisplays all connections and listening ports.
-bDisplays the executable involved in creating each connection or
listening port. In some cases well-known executables host
multiple independent components, and in these cases the
sequence of components involved in creating the connection
or listening port is displayed. In this case the executable
name is in [] at the bottom, on top is the component it called,
and so forth until TCP/IP was reached. Note that this option
can be time-consuming and will fail unless you have sufficient
permissions.
-eDisplays Ethernet statistics. This may be combined with the -s
option.
-nDisplays addresses and port numbers in numerical form.
-oDisplays the owning process ID associated with each connection.
-p protoShows connections for the protocol specified by proto; proto
may be any of: TCP, UDP, TCPv6, or UDPv6.If used with the -s
option to display per-protocol statistics, proto may be any of:
IP, IPv6, ICMP, ICMPv6, TCP, TCPv6, UDP, or UDPv6.
-rDisplays the routing table.
-sDisplays per-protocol statistics.By default, statistics are
shown for IP, IPv6, ICMP, ICMPv6, TCP, TCPv6, UDP, and UDPv6;
the -p option may be used to specify a subset of the default.
-vWhen used in conjunction with -b, will display sequence of
components involved in creating the connection or listening
port for all executables.
intervalRedisplays selected statistics, pausing interval seconds
between each display.Press CTRL+C to stop redisplaying
statistics.If omitted, netstat will print the current
configuration information once.netstat -an使用命令“netstat -n”就可以查看到了
C#,socket,能打开服务端cmd,能从服务端获取文件。
不是很明白能说详细点么追问

就是用C#写两个程序,一个客户端,一个服务端,客服端和服务端相连后客户端能通过打开服务端cmd控制服务端,还能获取服务端的文件。。追答

你补充的都不是重点重点是 打开cmd干嘛直接用process启动就好获取文件直接搜索盘符然后寻找么追问

我在学写一个后门程序。。想打开cmd,做所有想做的事追答

可以参考这个
就是用Process来做写后门程序也不用这样写,直接调用Windows的系统函数,exec之类的函数就可以了,cmd只是一个工具,它做不了你要的效果。
php socket实现群聊天室,服务器端可以不通过cmd运行么


因为只有了accept客户端才上,你如果accept下面接一个循环,那二个用户不是说能不这个循环,而是连不进……此时只有第一个用户break出了循环,然后程序回头再调用accept,第二个用户才能连上。 用多进程来处理如何?因为accept一.写成bat也行 shell也行
如何用Python编写一个聊天室

一、课程绍1.简介本次项目课是实现简单聊程序的服务器端和客户端。2.点服务器及到asyncore、asynchat和socket这几个模块,客户端用到了telnetlib、wx、time和thread这几个模块。3.所需环境本次课中编写客户端需要用到wxPython,它是一个GUI工具包,请先使用下面的命令安装:$ sudo apt-get install python-wxtools
密码为shiyanlou4.项目效果截图登录窗口聊天窗口二、项目实战(服务器端)1.服务器类首先需要一个聊天服务器,这里继承asyncore的dispatcher类来实现,代码如下class ChatServer(dispatcher):
"""
聊天服务器
"""

def __init__(self, port):
dispatcher.__init__(self)
self.create_socket(socket.AF_INET, socket.SOCK_STREAM)
self.set_reuse_addr()
self.bind(('', port))
self.listen(5)
self.users = {}
self.main_room = ChatRoom(self)

def handle_accept(self):
conn, addr = self.accept()
ChatSession(self, conn)
2.会话类有了服务器类还需要能维护每个用户的连接会话,这里继承asynchat的async_chat类来实现,代码如下:class ChatSession(async_chat):
"""
负责和单用户通信
"""

def __init__(self, server, sock):
async_chat.__init__(self, sock)
self.server = server
self.set_terminator(' ')
self.data = []
self.name = None
self.enter(LoginRoom(server))

def enter(self, room):
'从当前房间移除自身,然后添加到指定房间'
try:
cur = self.room
except AttributeError:
pass
else:
cur.remove(self)
self.room = room
room.add(self)

def collect_incoming_data(self, data):
'接受客户端的数据'
self.data.append(data)

def found_terminator(self):
'当客户端的一条数据结束时的处理'
line = ''.join(self.data)
self.data = []
try:
self.room.handle(self, line)
except EndSession:
self.handle_close()

def handle_close(self):
async_chat.handle_close(self)
self.enter(LogoutRoom(self.server))
3.命令解释器现在就需要一个命令解释器能够解释用户的命令,例如登录、查询在线用户和发消息等,代码如下:class CommandHandler:
"""
命令处理类
"""

def unknown(self, session, cmd):
'响应未知命令'
session.push('Unknown command: %s ' % cmd)

def handle(self, session, line):
'命令处理'
if not line.strip():
return
parts = line.split(' ', 1)
cmd = parts[0]
try:
line = parts[1].strip()
except IndexError:
line = ''
meth = getattr(self, 'do_' + cmd, None)
try:
meth(session, line)
except TypeError:
self.unknown(session, cmd)
4.房间接下来就需要实现聊天室的房间了,这里我们定义了三种房间,分别是用户刚登录时的房间、聊天的房间和退出登录的房间,这三种房间都有一个公共的父类,代码如下:class Room(CommandHandler):
"""
包含多个用户的环境,负责基本的命令处理和广播
"""

def __init__(self, server):
self.server = server
self.sessions = []

def add(self, session):
'一个用户进入房间'
self.sessions.append(session)

def remove(self, session):
'一个用户离开房间'
self.sessions.remove(session)

def broadcast(self, line):
'向所有的用户发送指定消息'
for session in self.sessions:
session.push(line)

def do_logout(self, session, line):
'退出房间'
raise EndSession

class LoginRoom(Room):
"""
刚登录的用户的房间
"""

def add(self, session):
'用户连接成功的回应'
Room.add(self, session)
session.push('Connect Success')

def do_login(self, session, line):
'登录命令处理'
name = line.strip()
if not name:
session.push('UserName Empty')
elif name in self.server.users:
session.push('UserName Exist')
else:
session.name = name
session.enter(self.server.main_room)

class ChatRoom(Room):
"""
聊天用的房间
"""

def add(self, session):
'广播新用户进入'
session.push('Login Success')
self.broadcast(session.name + ' has entered the room. ')
self.server.users[session.name] = session
Room.add(self, session)

def remove(self, session):
'广播用户离开'
Room.remove(self, session)
self.broadcast(session.name + ' has left the room. ')

def do_say(self, session, line):
'客户端发送消息'
self.broadcast(session.name + ': ' + line + ' ')

def do_look(self, session, line):
'查看在线用户'
session.push('Online Users: ')
for other in self.sessions:
session.push(other.name + ' ')

class LogoutRoom(Room):
"""
用户退出时的房间
"""

def add(self, session):
'从服务器中移除'
try:
del self.server.users[session.name]
except KeyError:
pass
5.服务器端完整代码#!/usr/bin/python
# encoding: utf-8

from asyncore import dispatcher
from asynchat import async_chat
import socket, asyncore

PORT = 6666 #端口

class EndSession(Exception):
"""
自定义会话结束时的异常
"""
pass

class CommandHandler:
"""
命令处理类
"""

def unknown(self, session, cmd):
'响应未知命令'
session.push('Unknown command: %s ' % cmd)

def handle(self, session, line):
'命令处理'
if not line.strip():
return
parts = line.split(' ', 1)
cmd = parts[0]
try:
line = parts[1].strip()
except IndexError:
line = ''
meth = getattr(self, 'do_' + cmd, None)
try:
meth(session, line)
except TypeError:
self.unknown(session, cmd)

class Room(CommandHandler):
"""
包含多个用户的环境,负责基本的命令处理和广播
"""

def __init__(self, server):
self.server = server
self.sessions = []

def add(self, session):
'一个用户进入房间'
self.sessions.append(session)

def remove(self, session):
'一个用户离开房间'
self.sessions.remove(session)

def broadcast(self, line):
'向所有的用户发送指定消息'
for session in self.sessions:
session.push(line)

def do_logout(self, session, line):
'退出房间'
raise EndSession

class LoginRoom(Room):
"""
刚登录的用户的房间
"""

def add(self, session):
'用户连接成功的回应'
Room.add(self, session)
session.push('Connect Success')

def do_login(self, session, line):
'登录命令处理'
name = line.strip()
if not name:
session.push('UserName Empty')
elif name in self.server.users:
session.push('UserName Exist')
else:
session.name = name
session.enter(self.server.main_room)

class ChatRoom(Room):
"""
聊天用的房间
"""

def add(self, session):
'广播新用户进入'
session.push('Login Success')
self.broadcast(session.name + ' has entered the room. ')
self.server.users[session.name] = session
Room.add(self, session)

def remove(self, session):
'广播用户离开'
Room.remove(self, session)
self.broadcast(session.name + ' has left the room. ')

def do_say(self, session, line):
'客户端发送消息'
self.broadcast(session.name + ': ' + line + ' ')

def do_look(self, session, line):
'查看在线用户'
session.push('Online Users: ')
for other in self.sessions:
session.push(other.name + ' ')

class LogoutRoom(Room):
"""
用户退出时的房间
"""

def add(self, session):
'从服务器中移除'
try:
del self.server.users[session.name]
except KeyError:
pass

class ChatSession(async_chat):
"""
负责和单用户通信
"""

def __init__(self, server, sock):
async_chat.__init__(self, sock)
self.server = server
self.set_terminator(' ')
self.data = []
self.name = None
self.enter(LoginRoom(server))

def enter(self, room):
'从当前房间移除自身,然后添加到指定房间'
try:
cur = self.room
except AttributeError:
pass
else:
cur.remove(self)
self.room = room
room.add(self)

def collect_incoming_data(self, data):
'接受客户端的数据'
self.data.append(data)

def found_terminator(self):
'当客户端的一条数据结束时的处理'
line = ''.join(self.data)
self.data = []
try:
self.room.handle(self, line)
except EndSession:
self.handle_close()

def handle_close(self):
async_chat.handle_close(self)
self.enter(LogoutRoom(self.server))

class ChatServer(dispatcher):
"""
聊天服务器
"""

def __init__(self, port):
dispatcher.__init__(self)
self.create_socket(socket.AF_INET, socket.SOCK_STREAM)
self.set_reuse_addr()
self.bind(('', port))
self.listen(5)
self.users = {}
self.main_room = ChatRoom(self)

def handle_accept(self):
conn, addr = self.accept()
ChatSession(self, conn)

if __name__ == '__main__':
s = ChatServer(PORT)
try:
asyncore.loop()
except KeyboardInterrupt:
print
三、项目实战(客户端)完成了服务器端后,就需要实现客户端了,这里客户端连接服务器使用了telnetlib模块。1.登录窗口这里的图形界面包选择了wxPython,前面有安装说明,登录窗口通过继承wx.Frame类来实现,代码如下:class LoginFrame(wx.Frame):
"""
登录窗口



上一篇: 下一篇: