-
Notifications
You must be signed in to change notification settings - Fork 0
/
tcp_client.py
executable file
·77 lines (44 loc) · 1.13 KB
/
tcp_client.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#!/usr/bin/python3
import socket
import threading
import sys
import os
RHOST="0.0.0.0"
RPORT=None
def GetArgs():
global RHOST
global RPORT
offset = 0
for index in range(1, len(sys.argv)):
arg = sys.argv[index+offset]
if(arg == "-h" or arg == "--help"):
help()
elif(arg == "-v" or arg == "-vv"):
sys.argv.remove(arg)
offset -= 1
help()
if(len(sys.argv) == 3):
RHOST = sys.argv[1]
RPORT = int(sys.argv[2])
else:
print("!!Argument Error!!")
help()
def help():
print("tcp_client.py [RHOST] [RPORT]")
sys.exit()
def main():
print("client started...\n")
GetArgs()
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.connect((RHOST,RPORT))
print("connected...\n")
while True:
message = input("Message:")
sock.sendall(message.encode("utf-8"))
if "Q" in message:
break
message = sock.recv(1024)
print("Server: %s" % message)
return
if __name__=="__main__":
main()