Last active
July 21, 2016 18:10
-
-
Save hiroshiro/79ece9807bd1a0bf38702a45ce2083c3 to your computer and use it in GitHub Desktop.
サイバーセキュリティプログラミングp14~16
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
import socket | |
target_host = "127.0.0.1" | |
target_port = 8080 | |
# ソケットオブジェクトの作成 | |
client = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | |
# サーバーへ接続 | |
client.connect((target_host,target_port)) | |
# データの送信 | |
client.sendto("AAABBBCCC", (target_host,target_port)) | |
# データの受信 | |
response = client.recv(4096) | |
print response |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
import socket | |
import threading | |
bind_ip = "0.0.0.0" | |
bind_port = 8080 | |
server =socket.socket(socket.AF_INET, socket.SOCK_STREAM) | |
server.bind((bind_ip,bind_port)) | |
server.listen(5) | |
print "[*] Received: %s:%d" % (bind_ip,bind_port) | |
# クライアントからの接続を処理するスレッド | |
def handle_client(client_socket): | |
# クライアントが送信してきたデータを表示 | |
request = client_socket.recv(1024) | |
print "[*] Received: %s" % request | |
# パケットの返送 | |
client_socket.send("ACK!") | |
client_socket.close() | |
while True: | |
client,addr = server.accept() | |
print "[*] Accepted connection from: %s:%d" % (addr[0],addr[1]) | |
# 受信データを処理するスレッドの起動 | |
client_handler = threading.Thread(target=handle_client,args=(client,)) | |
client_handler.start() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment