Home 0P3N Blog Tutorial: Socket Testing Tool Source Code
Ready to Start Your Career?
Create Free Account
Bmsr256 s profile image
By: Bmsr256
July 31, 2017

Tutorial: Socket Testing Tool Source Code

By: Bmsr256
July 31, 2017
Bmsr256 s profile image
By: Bmsr256
July 31, 2017
This time I will show you here a source code of a socket testing tool written in Python. This is a good, simple tool to test the Internet sockets using the IP of the target host and the port.Here's the source code:
`## Socket Testing Tool import sys import socket import getopt import threading import subprocesslisten = False command = False upload = False execute = "" target = "" upload_destination = "" port = 0def usage (): print "Testing NET Tool" print print "Usage: socket_testing.py -t target_host -p port" print "-l --listen - listen on [host]:[port] for incoming connections" print "-e --execute=file_to_run - execute the given file upon receiving a connection" print "-c --command - initialize a command shell" print "-u --upload=destination - upon receiving connection upload a file and write to [destination]" print print print "Examples: " print "socket_testing.py -t 192.168.1.1 -p 10000 -l c" print "socket_testing.py -t 192.168.1.1 -p 10000 -l -u=c:\payload.exe" print "socket_testing.py -t 192.168.1.1 -p 10000 -l -e="cat /etc/passwd"" print "echo 'ABCDEFGHI' | ./socket_testing.py -t 192.168.1.3 -p 135" sys.exit(0)def main(): global listen global port global execute global command global upload_destination global targetif not len(sys.argv[1:]): usage()try: opts, args = getopt.getopt(sys.argv[1:],"hle:t:p:cu:", ["help","listen","execute","target","port","command","upload"]) except getopt.GetoptError as err: print str(err) usage()for o,a in opts: if o in ("-h","--help"): usage() elif o in ("-l","--listen"): listen = True elif o in ("-e", "--execute"): execute = a elif o in ("-c", "--commandshell"): command = True elif o in ("-u", "--upload"): upload_destination = a elif o in ("-t", "--target"): target = a elif o in ("-p", "--port"): port = int(a) else: assert False,"Unhandled Option"if not listen and len(target) and port > 0: buffer = sys.stdin.read() client_sender(buffer)if listen: server_loop() main()`
 I hope you can learn with this tool. There are much more great examples in Python, but this is a small example. If you have questions, comment below or contact me directly.
Schedule Demo

Build your Cybersecurity or IT Career

Accelerate in your role, earn new certifications, and develop cutting-edge skills using the fastest growing catalog in the industry