1010from os import _exit
1111import json
1212from zlib import compress ,decompress
13+ from platform import system
1314
1415
1516class server :
1617
1718 def __init__ (self ,port ):
1819 self .ip = socket .gethostbyname (socket .gethostname ())
1920 self .port = port
21+ self .l = "cd"
22+ self .o = system ()
23+ if self .o == "Linux" :
24+ self .l = "pwd"
2025
2126 def start (self ):
2227 try :
@@ -28,12 +33,15 @@ def start(self):
2833 _exit (1 )
2934 try :
3035 so .listen (1 )
31- print "Waiting for connection ..."
36+ host = socket .gethostbyname (socket .gethostname ())
37+ print "[%s:%s] Waiting for connection ..." % (host ,self .port )
38+
39+
3240 while 1 :
33- host = socket . gethostbyname ( socket . gethostname ())
41+
3442 ob , address = so .accept ()
3543 print "Connected with %s " % address [0 ]
36- ob .send (compress (json .dumps ({"msg" :"Connected With %s" % host , "location" :self .__cmd ('cd' )[1 ]}).encode ()))
44+ ob .send (compress (json .dumps ({"msg" :"Connected With %s os at %s" % ( self . o , host ) , "location" :self .__cmd (self . l )[1 ]}).encode ()))
3745 while 1 :
3846 try :
3947 command = ob .recv (2048 )
@@ -63,15 +71,13 @@ def start(self):
6371 def __cmd (self ,command ):
6472 from os import popen
6573 try :
74+ q = popen (self .l ).read ()
6675 o = popen (command ).read ()
67- q = popen ( 'cd' ). read ()
76+
6877 return (o ,q )
6978 except :
7079 return "Sorry!! Command not executed"
7180
72-
73-
74-
7581class client :
7682
7783 def __init__ (self ,ip , port ):
@@ -105,10 +111,6 @@ def start(self):
105111 so .close ()
106112 _exit (1 )
107113
108-
109-
110-
111-
112114if __name__ == "__main__" :
113115
114116 try :
@@ -127,6 +129,6 @@ def start(self):
127129 s .start ()
128130
129131 except :
130- print "The Parameter provided are wrong \n \n \t Usage Format : shaker.y [client/server] [port] [ip{just for client}]"
132+ print "The Parameter provided are wrong \n \n \t Usage Format : shaker.py [client/server] [port] [ip{just for client}]"
131133 _exit (1 )
132134
0 commit comments