-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathssh_server.py
40 lines (27 loc) · 923 Bytes
/
ssh_server.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
#!/usr/bin/python3
import socket
import time
import subprocess
# creating UDP socket with ipv4 & this is rec side
#socket.socket() # by default TCP
# to create UDP socket
s=socket.socket(socket.AF_INET,socket.SOCK_DGRAM)
# recv ip and port
r_ip="192.168.10.100"
r_port=9900
# now binding both port and ip
s.bind((r_ip,r_port))
while True:
# to recv data from sender
recv_data=s.recvfrom(100)
# here recvfrom will recv data and ip port of sender
print(recv_data[0]) # this means data
print(recv_data[1]) # address of sender
print("@@@@@@@@@@@@@@@@@")
print("sending output to sender ")
result=subprocess.getstatusoutput(recv_data[0])
# check the success rate
if result[0] == 0 :
s.sendto(result[1].encode('ascii'),recv_data[1]) # sending output to sender
else :
s.sendto("command not found ".encode('ascii'),recv_data[1]) # sending output to sender