Skip to content

Instantly share code, notes, and snippets.

@nenodias
Created September 9, 2016 01:16
Show Gist options
  • Save nenodias/42b45a2956a19e92a19636be9ed1f555 to your computer and use it in GitHub Desktop.
Save nenodias/42b45a2956a19e92a19636be9ed1f555 to your computer and use it in GitHub Desktop.
# *-* coding:utf-8 *-*
import socket
import sys
reload(sys)
sys.setdefaultencoding('utf8')
xinput = None
try:
xinput = raw_input
except:
xinput = input
ativo = True
s = None
while True:
try:
ip = xinput('Digite o ip:')
porta = xinput('Digite a porta:')
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((ip, int(porta)))
comando = True
while True:
if comando:
comando = xinput(s.recv(2048))
if comando != 'exit' and comando:
s.send(comando)
elif comando == 'exit':
s.send(comando)
s.close()
ativo = False
break
if not ativo:
break
except Exception as ex:
print(ex)
break
finally:
s.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment