Created
July 26, 2017 10:49
-
-
Save nitinbhojwani/7f2dffd0b56fcc760d62ef4f928ffcb5 to your computer and use it in GitHub Desktop.
Send message over TCP connection given host and port
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def do_telnet(host, port, message): | |
import telnetlib | |
tn = telnetlib.Telnet(host, port) | |
ret = tn.write(message + '\n') | |
print "sent the message: %s" % message | |
tn.close() | |
def send_thru_socket(host, port, message): | |
TCP_IP = host | |
TCP_PORT = port | |
BUFFER_SIZE = 1024 | |
MESSAGE = message | |
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | |
try: | |
s.connect((TCP_IP, TCP_PORT)) | |
except: | |
print 'Unable to connect' | |
return | |
s.sendall(str(MESSAGE) + '\n') | |
print "Sent:", MESSAGE | |
#data = s.recv(1) | |
s.close() | |
#print "Response:", data |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment