Warning: session_start(): Cannot send session cookie - headers already sent by (output started at /home/circui15/public_html/packetpros.com/index.php:4) in /home/circui15/public_html/packetpros.com/wp-content/plugins/wp-file-upload/wordpress_file_upload.php on line 2

Warning: session_start(): Cannot send session cache limiter - headers already sent (output started at /home/circui15/public_html/packetpros.com/index.php:4) in /home/circui15/public_html/packetpros.com/wp-content/plugins/wp-file-upload/wordpress_file_upload.php on line 2
Server Ports w/python

In working with EVE-NG I often find that I need specific ports open on a test server. Instead of always installing an application (eg NGINX) I hacked together a python that will open a port.


import socket
import subprocess

print "---------------------------------------------------------"
print "This script will open any TCP port that is not currently"
print "in use. Below are the ports in use. Any port < 1024 will"
print "require sudo."
print "---------------------------------------------------------"
print " "

subprocess.check_output(['netstat', '-tulpn', '| grep tcp$'])

PORT = int(raw_input("What port do you want the server to run on? "))

if 1 <= PORT <= 65535:
print " "
print " That is not a valid TCP port. "

HOST = '' # Hostname to bind

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind((HOST, PORT))

print "Port", PORT,"is open ... "
conn, addr = s.accept()
print 'Connected by', addr
while 1:
data = conn.recv(1024)
if not data: break