質問編集履歴

2

スクリプト文字色の改善

2022/04/26 13:01

投稿

akisan55
akisan55

スコア49

test CHANGED
File without changes
test CHANGED
@@ -70,7 +70,7 @@
70
70
  main()
71
71
  ```
72
72
  TCPclient.py
73
- ```
73
+ ```python
74
74
  import socket
75
75
 
76
76
  target_host = '0.0.0.0'

1

スクリプト、環境情報の追加

2022/04/26 12:39

投稿

akisan55
akisan55

スコア49

test CHANGED
File without changes
test CHANGED
@@ -18,13 +18,99 @@
18
18
  ・client側PCで''netstat -an''を実行しても''0.0.0.0:5555''は有りませんでした。
19
19
  (server側では0.0.0.0:5555はLISTENING状態になっていました。)
20
20
  ・serverもclientも、自身のPCで通信したら、エラーは出なかった。
21
+ ・ネットワークに接続しているか。
21
22
  ### 環境
22
- server側:Windows10 64bit
23
+ server側:Windows11 64bit
24
+ IP:192.168.0.19
23
- client側:Windows1164bit
25
+ client側:Windows10 64bit
26
+ IP:192.168.0.13
27
+ ### ネットワーク構成
28
+ LANアダプターデフォルトゲートウェイ:192.168.0.1
29
+ サブネットマスク:255.255.255.0
30
+ (同じ一つのルーターを使用)
24
- 両方python 3.6
31
+ 両方python 3.6で実行
25
32
  ### 補足
26
33
  TCPserver.pyとTCPclient.pyは
27
34
  https://github.com/oreilly-japan/black-hat-python-2e-ja/blob/master/chapter-02
28
35
  を使いました。
36
+ ### 補足2
37
+ 説明不足で申し訳ありません。
38
+ 環境情報を追加しました。
39
+
40
+ TCPServer.py
41
+ ```python
42
+ import socket
43
+ import threading
44
+
45
+ IP = '0.0.0.0'
46
+ PORT = 5555
29
47
 
30
48
 
49
+ def main():
50
+ server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
51
+ server.bind((IP, PORT))
52
+ server.listen(5)
53
+ print(f'[*] Listening on {IP}:{PORT}')
54
+
55
+ while True:
56
+ client, address = server.accept()
57
+ print(f'[*] Accepted connection from {address[0]}:{address[1]}')
58
+ client_handler = threading.Thread(target=handle_client, args=(client,))
59
+ client_handler.start()
60
+
61
+
62
+ def handle_client(client_socket):
63
+ with client_socket as sock:
64
+ request = sock.recv(1024)
65
+ print(f'[*] Received: {request.decode("utf-8")}')
66
+ sock.send(b'ACK')
67
+
68
+
69
+ if __name__ == '__main__':
70
+ main()
71
+ ```
72
+ TCPclient.py
73
+ ```
74
+ import socket
75
+
76
+ target_host = '0.0.0.0'
77
+ target_port = 5555
78
+
79
+ # ソケットオブジェクトの作成
80
+ client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
81
+
82
+ # サーバーへ接続
83
+ client.connect((target_host,target_port))
84
+
85
+ # データの送信
86
+ client.send(b"GET / HTTP/1.1\r\nHost: google.com\r\n\r\n")
87
+
88
+ # データの受信
89
+ response = client.recv(4096)
90
+
91
+ print(response.decode())
92
+ client.close()
93
+ ```
94
+
95
+ tcpserver.pyでLISTENING状態にしてから``netstat -an``を実行した結果
96
+ ```
97
+ プロトコル ローカル アドレス 外部アドレス 状態
98
+ TCP 0.0.0.0:135 0.0.0.0:0 LISTENING
99
+ TCP 0.0.0.0:445 0.0.0.0:0 LISTENING
100
+ TCP 0.0.0.0:2869 0.0.0.0:0 LISTENING
101
+ TCP 0.0.0.0:5040 0.0.0.0:0 LISTENING
102
+ TCP 0.0.0.0:5357 0.0.0.0:0 LISTENING
103
+ TCP 0.0.0.0:7680 0.0.0.0:0 LISTENING
104
+ TCP 0.0.0.0:49664 0.0.0.0:0 LISTENING
105
+ TCP 0.0.0.0:49665 0.0.0.0:0 LISTENING
106
+ TCP 0.0.0.0:49666 0.0.0.0:0 LISTENING
107
+ TCP 0.0.0.0:49667 0.0.0.0:0 LISTENING
108
+ TCP 0.0.0.0:49668 0.0.0.0:0 LISTENING
109
+ TCP 0.0.0.0:49669 0.0.0.0:0 LISTENING
110
+ TCP 10.0.0.1:139 0.0.0.0:0 LISTENING
111
+
112
+ ~~~~~~~~~~~~~~~~~~~
113
+ ```
114
+ 0.0.0.0 5555が存在しない。
115
+
116
+