Home > Powershell > Opening a Port on a Windows machine using Powershell

Opening a Port on a Windows machine using Powershell

Quick one today . .

Someone in the office asked me how to quickly open a TCP port on a Windows host in order to do some firewall / port testing across vlans.

I figured, let’s do it in Powershell – pretty simple, just open an http listener.

Like so:

function open-socket ($port)
	{
	($prefix="http://+:$port/")
	# create an httplistener listening on the specified prefix url
	$listener = new-object Net.HttpListener
	$listener.Prefixes.Add($prefix)
	$listener.Start()
	}
	

Simple, just change the port number as applicable and job’s a good’un.

Categories: Powershell Tags:
  1. No comments yet.
  1. No trackbacks yet.
You must be logged in to post a comment.