-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsimpleclient.py
More file actions
38 lines (29 loc) · 846 Bytes
/
simpleclient.py
File metadata and controls
38 lines (29 loc) · 846 Bytes
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
#!/usr/bin/env python3
"""Client
Creates a client to connect to a given IP and port
Usage: $ python3 simpleclient <IP> <port>
"""
import socket
import sys
def client(ip: str, port: str) -> None:
"""Starts a simple client with given arguments
Args:
ip (str): The IP of the server
port (str): The port of the server
"""
try:
port = int(port)
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.connect((ip, port))
msg = sock.recv(1024)
msg = msg.decode("ascii")
sock.close()
print(f"[+] {msg}")
except:
print(f"[-] Client failed: {e}")
sys.exit(1)
if __name__ == "__main__":
if len(sys.argv) < 3:
print(f"[!] Usage: python3 {sys.argv[0]} <IP> <port>")
sys.exit(1)
client(sys.argv[1], sys.argv[2])