-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsocket_2.py
More file actions
36 lines (29 loc) · 710 Bytes
/
Copy pathsocket_2.py
File metadata and controls
36 lines (29 loc) · 710 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
#!/usr/bin/env python3
import socket
import sys
def qotd_client(addr='djxmmx.net',port=17):
s = socket.socket()
s.connect((addr,port))
chunk = s.recv(1)
msg = bytearray()
while chunk:
msg.extend(chunk)
chunk = s.recv(1)
print(msg.decode('ascii'))
def daytime(addr='8.8.8.8',port=80):
s = socket.socket()
s.settimeout(5)
try:
s.connect((addr,port))
except socket.timeout:
print('failed to connect')
sys.exit(1)
msg = bytearray()
chunk = s.recv(32)
while chunk:
msg.extend(chunk)
chunk = s.recv(32)
return msg.decode('ascii')
if __name__ == '__main__':
#qotd_client()
print(daytime())