python Socket執行個體練習

來源:互聯網
上載者:User

標籤:port   exce   資料   end   config   std   特定   add   encode   

簡單的通訊端通訊

server

import socketsock_server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)sock_server.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)  # 重用地址連接埠sock_server.bind((‘127.0.0.1‘, 8088))sock_server.listen(1)  # 開始監聽,1代表在允許有一個串連排隊,更多的新串連連進來時就會被拒絕print(‘starting...‘)while True:    conn, client_addr = sock_server.accept()  # 阻塞直到有串連為止,有了一個新串連進來後,就會為這個請求產生一個連線物件    print(client_addr)    while True:        try:            data = conn.recv(1024) # 接收1024個位元組            if not data: break  # 適用於linux作業系統,防止用戶端中斷連線後死迴圈            print(‘用戶端的資料‘, data)            conn.sendall(data.upper())  # 把收到的資料再全部返回給用戶端        except ConnectionResetError:  # 適用於windows作業系統,防止用戶端中斷連線後死迴圈            break    conn.close()server.close()

client

import socketclient = socket.socket(socket.AF_INET, socket.SOCK_STREAM)print(client)client.connect((‘127.0.0.1‘, 8088))while True:    data = input(‘input >>>‘)    if not data:  # 如果資料為空白,繼續輸入        continue    client.send(data.encode(‘utf-8‘))  # 發送資料    data = client.recv(1024)   # 接收資料    print(‘接收資料 =‘ , data.decode())client.close()  # 關閉

server輸出

starting...(‘127.0.0.1‘, 4612)用戶端的資料 b‘hellp‘用戶端的資料 b‘java‘(‘127.0.0.1‘, 4618)用戶端的資料 b‘abc‘用戶端的資料 b‘cd‘

 client1輸出

<socket.socket fd=216, family=AddressFamily.AF_INET, type=SocketKind.SOCK_STREAM, proto=0>input >>>hellp接收資料 = HELLPinput >>>java接收資料 = JAVAinput >>>Process finished with exit code -1 # 關閉client1

 client2輸出

<socket.socket fd=216, family=AddressFamily.AF_INET, type=SocketKind.SOCK_STREAM, proto=0>input >>>abc接收資料 = ABCinput >>>cd接收資料 = CDinput >>>
類比ssh遠程執行命令  

sever端

import socketimport subprocessdef cmd_exec(cmd):    """    執行shell命令    :param cmd:    :return:    """    p = subprocess.Popen(cmd, shell=True,    stdin=subprocess.PIPE,stdout=subprocess.PIPE,stderr=subprocess.PIPE)    stdout, stderr = p.communicate()    if p.returncode != 0:        return stderr    return stdoutsock_server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)sock_server.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)  # 重用地址連接埠sock_server.bind((‘127.0.0.1‘, 8088))sock_server.listen(1)  # 開始監聽,1代表在允許有一個串連排隊,更多的新串連連進來時就會被拒絕print(‘starting...‘)while True:    conn, client_addr = sock_server.accept()  # 阻塞直到有串連為止,有了一個新串連進來後,就會為這個請求產生一個連線物件    print(client_addr)    while True:        try:            data = conn.recv(1024) # 接收1024個位元組            if not data: break  # 適用於linux作業系統,防止用戶端中斷連線後死迴圈            print(‘用戶端的命令‘, data.decode(‘GBK‘))            res = cmd_exec(data.decode(‘GBK‘))  # 執行cmd命令            print(res)            conn.sendall(res)  # 把收到的資料再全部返回給用戶端        except ConnectionResetError:  # 適用於windows作業系統,防止用戶端中斷連線後死迴圈            break    conn.close()server.close()

client端

import socketclient = socket.socket(socket.AF_INET, socket.SOCK_STREAM)print(client)client.connect((‘127.0.0.1‘, 8088))while True:    data = input(‘input >>>‘)    if not data:  # 如果資料為空白,繼續輸入        continue    client.send(data.encode(‘GBK‘))  # 發送資料    response = bytes()    data = client.recv(1024)   # 接收資料    print(‘接收資料 =‘, data.decode(‘gbk‘, ‘ignore‘))  # 如果設定為ignore,則會忽略非法字元; client.close()  # 關閉 

server輸出

 

starting...(‘127.0.0.1‘, 6091)用戶端的命令 ipconfig/all7705 b‘\r\nWindows IP \xc5\xe4\xd6\xc3\r\n\r\n   \xd6\xf7\xbb\xfa\xc3\xfb  . . . . . . . . . . . . . : jingjing-PC\r\n   \xd6\xf7 DNS \xba\xf3\xd7\xba . . . . . . . . . . . : \r\n   \xbd\xda\xb5\xe3\xc0\xe0\xd0\xcd  . . . . . . . . . . . . : \xbb\xec\xba\xcf\r\n   IP \xc2\xb7\xd3\xc9\xd2\xd1\xc6\xf4\xd3\xc3 . . . . . . . . . . : \xb7\xf1\r\n   WINS \xb4\xfa\xc0\xed\xd2\xd1\xc6\xf4\xd3\xc3 . . . . . . . . . : \xb7\xf1\r\n\r\n\xd2\xd4\xcc\xab\xcd\xf8\xca\xca\xc5\xe4\xc6\xf7 \xb1\xbe\xb5\xd8\xc1\xac\xbd\xd3 3:\r\n\r\n   \xc3\xbd\xcc\xe5\xd7\xb4\xcc\xac  . . . . . . . . . . . . : \xc3\xbd\xcc\xe5\xd2\xd1\xb6\xcf\xbf\xaa\r\n   \xc1\xac\xbd\xd3\xcc\xd8\xb6\xa8\xb5\xc4 DNS \xba\xf3\xd7\xba . . . . . . . : \r\n   \xc3\xe8\xca\xf6. . . . . . . . . . . . . . . : Bluetooth PAN Network Adapter\r\n   \xce\xef\xc0\xed\xb5\xd8\xd6\xb7. . . . . . . . . . . . . : 60-F8-1D-AD-89-EF\r\n   DHCP \xd2\xd1\xc6\xf4\xd3\xc3 . . . . . . . . . . . : \xca\xc7\r\n   \xd7\xd4\xb6\xaf\xc5\xe4\xd6\xc3\xd2\xd1\xc6\xf4\xd3\xc3. . . . . . . . . . : \xca\xc7\r\n\r\n\xce\xde\xcf\xdf\xbe\xd6\xd3\xf2\xcd\xf8\xca\xca\xc5\xe4\xc6\xf7 \xce\xde\xcf\xdf\xcd\xf8\xc2\xe7\xc1\xac\xbd\xd3:\r\n\r\n   \xc1\xac\xbd\xd3\xcc\xd8\xb6\xa8\xb5\xc4 DNS \xba\xf3\xd7\xba . . . . . . . : \r\n   \xc3\xe8\xca\xf6. . . . . . . . . . . . . . . : Broadcom 802.11ac Network Adapter\r\n   \xce\xef\xc0\xed\xb5\xd8\xd6\xb7. . . . . . . . . . . . . : 60-F8-1D-AD-89-EE\r\n   DHCP \xd2\xd1\xc6\xf4\xd3\xc3 . . . . . . . . . . . : \xca\xc7\r\n   \xd7\xd4\xb6\xaf\xc5\xe4\xd6\xc3\xd2\xd1\xc6\xf4\xd3\xc3. . . . . . . . . . : \xca\xc7\r\n   \xb1\xbe\xb5\xd8\xc1\xb4\xbd\xd3 IPv6 \xb5\xd8\xd6\xb7. . . . . . . . : fe80::55d1:e185:f929:8ce3%13(\xca\xd7\xd1\xa1) \r\n   IPv4 \xb5\xd8\xd6\xb7 . . . . . . . . . . . . : 192.168.31.125(\xca\xd7\xd1\xa1) \r\n   \xd7\xd3\xcd\xf8\xd1\xda\xc2\xeb  . . . . . . . . . . . . : 255.255.255.0\r\n   \xbb\xf1\xb5\xc3\xd7\xe2\xd4\xbc\xb5\xc4\xca\xb1\xbc\xe4  . . . . . . . . . : 2018\xc4\xea7\xd4\xc25\xc8\xd5 20:46:29\r\n   \xd7\xe2\xd4\xbc\xb9\xfd\xc6\xda\xb5\xc4\xca\xb1\xbc\xe4  . . . . . . . . . : 2018\xc4\xea7\xd4\xc26\xc8\xd5 8:46:29\r\n   \xc4\xac\xc8\xcf\xcd\xf8\xb9\xd8. . . . . . . . . . . . . : 192.168.31.1\r\n   DHCP \xb7\xfe\xce\xf1\xc6\xf7 . . . . . . . . . . . : 192.168.31.1\r\n   DHCPv6 IAID . . . . . . . . . . . : 291567645\r\n   DHCPv6 \xbf\xcd\xbb\xa7\xb6\xcb DUID  . . . . . . . : 00-01-00-01-21-7C-0D-6E-60-F8-1D-AD-89-EE\r\n   DNS \xb7\xfe\xce\xf1\xc6\xf7  . . . . . . . . . . . : 114.114.114.114\r\n   TCPIP \xc9\xcf\xb5\xc4 NetBIOS  . . . . . . . : \xd2\xd1\xc6\xf4\xd3\xc3\r\n\r\n\xd2\xd4\xcc\xab\xcd\xf8\xca\xca\xc5\xe4\xc6\xf7 VirtualBox Host-Only Network:\r\n\r\n   \xc1\xac\xbd\xd3\xcc\xd8\xb6\xa8\xb5\xc4 DNS \xba\xf3\xd7\xba . . . . . . . : \r\n   \xc3\xe8\xca\xf6. . . . . . . . . . . . . . . : VirtualBox Host-Only Ethernet Adapter\r\n   \xce\xef\xc0\xed\xb5\xd8\xd6\xb7. . . . . . . . . . . . . : 0A-00-27-00-00-13\r\n   DHCP \xd2\xd1\xc6\xf4\xd3\xc3 . . . . . . . . . . . : \xb7\xf1\r\n   \xd7\xd4\xb6\xaf\xc5\xe4\xd6\xc3\xd2\xd1\xc6\xf4\xd3\xc3. . . . . . . . . . : \xca\xc7\r\n   \xb1\xbe\xb5\xd8\xc1\xb4\xbd\xd3 IPv6 \xb5\xd8\xd6\xb7. . . . . . . . : fe80::7d26:2c96:84f1:6c4d%19(\xca\xd7\xd1\xa1) \r\n   \xd7\xd4\xb6\xaf\xc5\xe4\xd6\xc3 IPv4 \xb5\xd8\xd6\xb7  . . . . . . . : 169.254.108.77(\xca\xd7\xd1\xa1) \r\n   \xd7\xd3\xcd\xf8\xd1\xda\xc2\xeb  . . . . . . . . . . . . : 255.255.0.0\r\n   \xc4\xac\xc8\xcf\xcd\xf8\xb9\xd8. . . . . . . . . . . . . : 192.168.56.255\r\n   DHCPv6 IAID . . . . . . . . . . . : 336199719\r\n   DHCPv6 \xbf\xcd\xbb\xa7\xb6\xcb DUID  . . . . . . . : 00-01-00-01-21-7C-0D-6E-60-F8-1D-AD-89-EE\r\n   DNS \xb7\xfe\xce\xf1\xc6\xf7  . . . . . . . . . . . : fec0:0:0:ffff::1%1\r\n                                       fec0:0:0:ffff::2%1\r\n                                       fec0:0:0:ffff::3%1\r\n   TCPIP \xc9\xcf\xb5\xc4 NetBIOS  . . . . . . . : \xd2\xd1\xc6\xf4\xd3\xc3\r\n\r\n\xd2\xd4\xcc\xab\xcd\xf8\xca\xca\xc5\xe4\xc6\xf7 VirtualBox Host-Only Network #2:\r\n\r\n   \xc1\xac\xbd\xd3\xcc\xd8\xb6\xa8\xb5\xc4 DNS \xba\xf3\xd7\xba . . . . . . . : \r\n   \xc3\xe8\xca\xf6. . . . . . . . . . . . . . . : VirtualBox Host-Only Ethernet Adapter #2\r\n   \xce\xef\xc0\xed\xb5\xd8\xd6\xb7. . . . . . . . . . . . . : 0A-00-27-00-00-14\r\n   DHCP \xd2\xd1\xc6\xf4\xd3\xc3 . . . . . . . . . . . : \xb7\xf1\r\n   \xd7\xd4\xb6\xaf\xc5\xe4\xd6\xc3\xd2\xd1\xc6\xf4\xd3\xc3. . . . . . . . . . : \xca\xc7\r\n   \xb1\xbe\xb5\xd8\xc1\xb4\xbd\xd3 IPv6 \xb5\xd8\xd6\xb7. . . . . . . . : fe80::641c:b67e:fa43:a28d%20(\xca\xd7\xd1\xa1) \r\n   IPv4 \xb5\xd8\xd6\xb7 . . . . . . . . . . . . : 192.168.96.1(\xca\xd7\xd1\xa1) \r\n   \xd7\xd3\xcd\xf8\xd1\xda\xc2\xeb  . . . . . . . . . . . . : 255.255.255.0\r\n   \xc4\xac\xc8\xcf\xcd\xf8\xb9\xd8. . . . . . . . . . . . . : \r\n   DHCPv6 IAID . . . . . . . . . . . : 537526311\r\n   DHCPv6 \xbf\xcd\xbb\xa7\xb6\xcb DUID  . . . . . . . : 00-01-00-01-21-7C-0D-6E-60-F8-1D-AD-89-EE\r\n   DNS \xb7\xfe\xce\xf1\xc6\xf7  . . . . . . . . . . . : fec0:0:0:ffff::1%1\r\n                                       fec0:0:0:ffff::2%1\r\n                                       fec0:0:0:ffff::3%1\r\n   TCPIP \xc9\xcf\xb5\xc4 NetBIOS  . . . . . . . : \xd2\xd1\xc6\xf4\xd3\xc3\r\n\r\n\xd2\xd4\xcc\xab\xcd\xf8\xca\xca\xc5\xe4\xc6\xf7 VMware Network Adapter VMnet1:\r\n\r\n   \xc1\xac\xbd\xd3\xcc\xd8\xb6\xa8\xb5\xc4 DNS \xba\xf3\xd7\xba . . . . . . . : \r\n   \xc3\xe8\xca\xf6. . . . . . . . . . . . . . . : VMware Virtual Ethernet Adapter for VMnet1\r\n   \xce\xef\xc0\xed\xb5\xd8\xd6\xb7. . . . . . . . . . . . . : 00-50-56-C0-00-01\r\n   DHCP \xd2\xd1\xc6\xf4\xd3\xc3 . . . . . . . . . . . : \xca\xc7\r\n   \xd7\xd4\xb6\xaf\xc5\xe4\xd6\xc3\xd2\xd1\xc6\xf4\xd3\xc3. . . . . . . . . . : \xca\xc7\r\n   \xb1\xbe\xb5\xd8\xc1\xb4\xbd\xd3 IPv6 \xb5\xd8\xd6\xb7. . . . . . . . : fe80::20c1:b2f0:8bff:626c%25(\xca\xd7\xd1\xa1) \r\n   IPv4 \xb5\xd8\xd6\xb7 . . . . . . . . . . . . : 192.168.109.1(\xca\xd7\xd1\xa1) \r\n   \xd7\xd3\xcd\xf8\xd1\xda\xc2\xeb  . . . . . . . . . . . . : 255.255.255.0\r\n   \xbb\xf1\xb5\xc3\xd7\xe2\xd4\xbc\xb5\xc4\xca\xb1\xbc\xe4  . . . . . . . . . : 2018\xc4\xea7\xd4\xc25\xc8\xd5 20:46:20\r\n   \xd7\xe2\xd4\xbc\xb9\xfd\xc6\xda\xb5\xc4\xca\xb1\xbc\xe4  . . . . . . . . . : 2018\xc4\xea7\xd4\xc25\xc8\xd5 23:46:20\r\n   \xc4\xac\xc8\xcf\xcd\xf8\xb9\xd8. . . . . . . . . . . . . : \r\n   DHCP \xb7\xfe\xce\xf1\xc6\xf7 . . . . . . . . . . . : 192.168.109.254\r\n   DHCPv6 IAID . . . . . . . . . . . : 385896534\r\n   DHCPv6 \xbf\xcd\xbb\xa7\xb6\xcb DUID  . . . . . . . : 00-01-00-01-21-7C-0D-6E-60-F8-1D-AD-89-EE\r\n   DNS \xb7\xfe\xce\xf1\xc6\xf7  . . . . . . . . . . . : fec0:0:0:ffff::1%1\r\n                                       fec0:0:0:ffff::2%1\r\n                                       fec0:0:0:ffff::3%1\r\n   TCPIP \xc9\xcf\xb5\xc4 NetBIOS  . . . . . . . : \xd2\xd1\xc6\xf4\xd3\xc3\r\n\r\n\xd2\xd4\xcc\xab\xcd\xf8\xca\xca\xc5\xe4\xc6\xf7 VMware Network Adapter VMnet8:\r\n\r\n   \xc1\xac\xbd\xd3\xcc\xd8\xb6\xa8\xb5\xc4 DNS \xba\xf3\xd7\xba . . . . . . . : \r\n   \xc3\xe8\xca\xf6. . . . . . . . . . . . . . . : VMware Virtual Ethernet Adapter for VMnet8\r\n   \xce\xef\xc0\xed\xb5\xd8\xd6\xb7. . . . . . . . . . . . . : 00-50-56-C0-00-08\r\n   DHCP \xd2\xd1\xc6\xf4\xd3\xc3 . . . . . . . . . . . : \xca\xc7\r\n   \xd7\xd4\xb6\xaf\xc5\xe4\xd6\xc3\xd2\xd1\xc6\xf4\xd3\xc3. . . . . . . . . . : \xca\xc7\r\n   \xb1\xbe\xb5\xd8\xc1\xb4\xbd\xd3 IPv6 \xb5\xd8\xd6\xb7. . . . . . . . : fe80::61fd:5f66:1f70:cb3d%26(\xca\xd7\xd1\xa1) \r\n   IPv4 \xb5\xd8\xd6\xb7 . . . . . . . . . . . . : 192.168.5.1(\xca\xd7\xd1\xa1) \r\n   \xd7\xd3\xcd\xf8\xd1\xda\xc2\xeb  . . . . . . . . . . . . : 255.255.255.0\r\n   \xbb\xf1\xb5\xc3\xd7\xe2\xd4\xbc\xb5\xc4\xca\xb1\xbc\xe4  . . . . . . . . . : 2018\xc4\xea7\xd4\xc25\xc8\xd5 20:46:21\r\n   \xd7\xe2\xd4\xbc\xb9\xfd\xc6\xda\xb5\xc4\xca\xb1\xbc\xe4  . . . . . . . . . : 2018\xc4\xea7\xd4\xc25\xc8\xd5 23:46:21\r\n   \xc4\xac\xc8\xcf\xcd\xf8\xb9\xd8. . . . . . . . . . . . . : \r\n   DHCP \xb7\xfe\xce\xf1\xc6\xf7 . . . . . . . . . . . : 192.168.5.254\r\n   DHCPv6 IAID . . . . . . . . . . . : 402673750\r\n   DHCPv6 \xbf\xcd\xbb\xa7\xb6\xcb DUID  . . . . . . . : 00-01-00-01-21-7C-0D-6E-60-F8-1D-AD-89-EE\r\n   DNS \xb7\xfe\xce\xf1\xc6\xf7  . . . . . . . . . . . : fec0:0:0:ffff::1%1\r\n                                       fec0:0:0:ffff::2%1\r\n                                       fec0:0:0:ffff::3%1\r\n   \xd6\xf7 WINS \xb7\xfe\xce\xf1\xc6\xf7  . . . . . . . . . : 192.168.5.2\r\n   TCPIP \xc9\xcf\xb5\xc4 NetBIOS  . . . . . . . : \xd2\xd1\xc6\xf4\xd3\xc3\r\n\r\n\xcb\xed\xb5\xc0\xca\xca\xc5\xe4\xc6\xf7 \xb1\xbe\xb5\xd8\xc1\xac\xbd\xd3* 14:\r\n\r\n   \xc3\xbd\xcc\xe5\xd7\xb4\xcc\xac  . . . . . . . . . . . . : \xc3\xbd\xcc\xe5\xd2\xd1\xb6\xcf\xbf\xaa\r\n   \xc1\xac\xbd\xd3\xcc\xd8\xb6\xa8\xb5\xc4 DNS \xba\xf3\xd7\xba . . . . . . . : \r\n   \xc3\xe8\xca\xf6. . . . . . . . . . . . . . . : Microsoft ISATAP Adapter #2\r\n   \xce\xef\xc0\xed\xb5\xd8\xd6\xb7. . . . . . . . . . . . . : 00-00-00-00-00-00-00-E0\r\n   DHCP \xd2\xd1\xc6\xf4\xd3\xc3 . . . . . . . . . . . : \xb7\xf1\r\n   \xd7\xd4\xb6\xaf\xc5\xe4\xd6\xc3\xd2\xd1\xc6\xf4\xd3\xc3. . . . . . . . . . : \xca\xc7\r\n\r\n\xcb\xed\xb5\xc0\xca\xca\xc5\xe4\xc6\xf7 Teredo Tunneling Pseudo-Interface:\r\n\r\n   \xc3\xbd\xcc\xe5\xd7\xb4\xcc\xac  . . . . . . . . . . . . : \xc3\xbd\xcc\xe5\xd2\xd1\xb6\xcf\xbf\xaa\r\n   \xc1\xac\xbd\xd3\xcc\xd8\xb6\xa8\xb5\xc4 DNS \xba\xf3\xd7\xba . . . . . . . : \r\n   \xc3\xe8\xca\xf6. . . . . . . . . . . . . . . : Teredo Tunneling Pseudo-Interface\r\n   \xce\xef\xc0\xed\xb5\xd8\xd6\xb7. . . . . . . . . . . . . : 00-00-00-00-00-00-00-E0\r\n   DHCP \xd2\xd1\xc6\xf4\xd3\xc3 . . . . . . . . . . . : \xb7\xf1\r\n   \xd7\xd4\xb6\xaf\xc5\xe4\xd6\xc3\xd2\xd1\xc6\xf4\xd3\xc3. . . . . . . . . . : \xca\xc7\r\n\r\n\xcb\xed\xb5\xc0\xca\xca\xc5\xe4\xc6\xf7 isatap.{0DA4A980-7247-4922-AAFB-55760B865C15}:\r\n\r\n   \xc3\xbd\xcc\xe5\xd7\xb4\xcc\xac  . . . . . . . . . . . . : \xc3\xbd\xcc\xe5\xd2\xd1\xb6\xcf\xbf\xaa\r\n   \xc1\xac\xbd\xd3\xcc\xd8\xb6\xa8\xb5\xc4 DNS \xba\xf3\xd7\xba . . . . . . . : \r\n   \xc3\xe8\xca\xf6. . . . . . . . . . . . . . . : Microsoft ISATAP Adapter #3\r\n   \xce\xef\xc0\xed\xb5\xd8\xd6\xb7. . . . . . . . . . . . . : 00-00-00-00-00-00-00-E0\r\n   DHCP \xd2\xd1\xc6\xf4\xd3\xc3 . . . . . . . . . . . : \xb7\xf1\r\n   \xd7\xd4\xb6\xaf\xc5\xe4\xd6\xc3\xd2\xd1\xc6\xf4\xd3\xc3. . . . . . . . . . : \xca\xc7\r\n\r\n\xcb\xed\xb5\xc0\xca\xca\xc5\xe4\xc6\xf7 isatap.localdomain:\r\n\r\n   \xc3\xbd\xcc\xe5\xd7\xb4\xcc\xac  . . . . . . . . . . . . : \xc3\xbd\xcc\xe5\xd2\xd1\xb6\xcf\xbf\xaa\r\n   \xc1\xac\xbd\xd3\xcc\xd8\xb6\xa8\xb5\xc4 DNS \xba\xf3\xd7\xba . . . . . . . : \r\n   \xc3\xe8\xca\xf6. . . . . . . . . . . . . . . : Microsoft ISATAP Adapter #5\r\n   \xce\xef\xc0\xed\xb5\xd8\xd6\xb7. . . . . . . . . . . . . : 00-00-00-00-00-00-00-E0\r\n   DHCP \xd2\xd1\xc6\xf4\xd3\xc3 . . . . . . . . . . . : \xb7\xf1\r\n   \xd7\xd4\xb6\xaf\xc5\xe4\xd6\xc3\xd2\xd1\xc6\xf4\xd3\xc3. . . . . . . . . . : \xca\xc7\r\n\r\n\xcb\xed\xb5\xc0\xca\xca\xc5\xe4\xc6\xf7 \xb1\xbe\xb5\xd8\xc1\xac\xbd\xd3* 15:\r\n\r\n   \xc3\xbd\xcc\xe5\xd7\xb4\xcc\xac  . . . . . . . . . . . . : \xc3\xbd\xcc\xe5\xd2\xd1\xb6\xcf\xbf\xaa\r\n   \xc1\xac\xbd\xd3\xcc\xd8\xb6\xa8\xb5\xc4 DNS \xba\xf3\xd7\xba . . . . . . . : \r\n   \xc3\xe8\xca\xf6. . . . . . . . . . . . . . . : Microsoft ISATAP Adapter #6\r\n   \xce\xef\xc0\xed\xb5\xd8\xd6\xb7. . . . . . . . . . . . . : 00-00-00-00-00-00-00-E0\r\n   DHCP \xd2\xd1\xc6\xf4\xd3\xc3 . . . . . . . . . . . : \xb7\xf1\r\n   \xd7\xd4\xb6\xaf\xc5\xe4\xd6\xc3\xd2\xd1\xc6\xf4\xd3\xc3. . . . . . . . . . : \xca\xc7\r\n\r\n\xcb\xed\xb5\xc0\xca\xca\xc5\xe4\xc6\xf7 isatap.{94C5F926-3E20-4589-A88E-54A36934D42C}:\r\n\r\n   \xc3\xbd\xcc\xe5\xd7\xb4\xcc\xac  . . . . . . . . . . . . : \xc3\xbd\xcc\xe5\xd2\xd1\xb6\xcf\xbf\xaa\r\n   \xc1\xac\xbd\xd3\xcc\xd8\xb6\xa8\xb5\xc4 DNS \xba\xf3\xd7\xba . . . . . . . : \r\n   \xc3\xe8\xca\xf6. . . . . . . . . . . . . . . : Microsoft ISATAP Adapter #8\r\n   \xce\xef\xc0\xed\xb5\xd8\xd6\xb7. . . . . . . . . . . . . : 00-00-00-00-00-00-00-E0\r\n   DHCP \xd2\xd1\xc6\xf4\xd3\xc3 . . . . . . . . . . . : \xb7\xf1\r\n   \xd7\xd4\xb6\xaf\xc5\xe4\xd6\xc3\xd2\xd1\xc6\xf4\xd3\xc3. . . . . . . . . . : \xca\xc7\r\n‘用戶端的命令 ls61 b"‘ls‘ \xb2\xbb\xca\xc7\xc4\xda\xb2\xbf\xbb\xf2\xcd\xe2\xb2\xbf\xc3\xfc\xc1\xee\xa3\xac\xd2\xb2\xb2\xbb\xca\xc7\xbf\xc9\xd4\xcb\xd0\xd0\xb5\xc4\xb3\xcc\xd0\xf2\r\n\xbb\xf2\xc5\xfa\xb4\xa6\xc0\xed\xce\xc4\xbc\xfe\xa1\xa3\r\n"

 

  

client輸出

input >>>ipconfig/all接收資料 = Windows IP 配置   主機名稱  . . . . . . . . . . . . . : -PC   主 DNS 尾碼 . . . . . . . . . . . :    節點類型  . . . . . . . . . . . . : 混合   IP 路由已啟用 . . . . . . . . . . : 否   WINS 代理已啟用 . . . . . . . . . : 否乙太網路適配器 本地串連 3:   媒體狀態  . . . . . . . . . . . . : 媒體已斷開   串連特定的 DNS 尾碼 . . . . . . . :    描述. . . . . . . . . . . . . . . : Bluetooth PAN Network Adapter   物理地址. . . . . . . . . . . . . : 60-F8-1D-AD-89-EF   DHCP 已啟用 . . . . . . . . . . . : 是   自動設定已啟用. . . . . . . . . . : 是無線區域網路適配器 無線網路串連:   串連特定的 DNS 尾碼 . . . . . . . :    描述. . . . . . . . . . . . . . . : Broadcom 802.11ac Network Adapter   物理地址. . . . . . . . . . . . . : 60-F8-1D-AD-89-EE   DHCP 已啟用 . . . . . . . . . . . : 是   自動設定已啟用. . . . . . . . . . : 是   本地連結 IPv6 地址. . . . . . . . : fe80::55d1:e185:f929:8ce3%13(首選)    IPv4 地址 . . . . . . . . . . . . : 192.168.31.125(首選)    子網掩input >>>ls接收資料 =   . . . . . . . . . . . . : 255.255.255.0   獲得租約的時間  . . . . . . . . . : 2018年7月5日 20:46:29   租約到期的時間  . . . . . . . . . : 2018年7月6日 8:46:29   預設閘道. . . . . . . . . . . . . : 192.168.31.1   DHCP 伺服器 . . . . . . . . . . . : 192.168.31.1   DHCPv6 IAID . . . . . . . . . . . : 291567645   DHCPv6 用戶端 DUID  . . . . . . . : 00-01-00-01-21-7C-0D-6E-60-F8-1D-AD-89-EE   DNS 伺服器  . . . . . . . . . . . : 114.114.114.114   TCPIP 上的 NetBIOS  . . . . . . . : 已啟用乙太網路適配器 VirtualBox Host-Only Network:   串連特定的 DNS 尾碼 . . . . . . . :    描述. . . . . . . . . . . . . . . : VirtualBox Host-Only Ethernet Adapter   物理地址. . . . . . . . . . . . . : 0A-00-27-00-00-13   DHCP 已啟用 . . . . . . . . . . . : 否   自動設定已啟用. . . . . . . . . . : 是   本地連結 IPv6 地址. . . . . . . . : fe80::7d26:2c96:84f1:6c4d%19(首選)    自動設定 IPv4 地址  . . . . . . . : 169.254.108.77(首選)    子網路遮罩  . . . . . . . . . . . . : 255.255.0.0   預設閘道. . input >>> #出現粘包現象

  

  

python Socket執行個體練習

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.