HoBa
HoBa

Reputation: 3604

Network port listener on c#

I'm trying to listen the active ports on my network. I tried HttpListener, but I'm not sure if this is the right listener. Any ideas or examples?

using (m_listener = new HttpListener())
{ 
m_listener.Prefixes.Add("http://*:8080/"); 
m_listener.Start(); 
while (m_listener.IsListening)
{ 
HttpListenerContext context = m_listener.GetContext(); 
HttpListenerRequest request = context.Request; 
HttpListenerResponse response = context.Response; 
textBox1.Text += request.RawUrl + "\r\n"; 
textBox1.Text += request.UserHostName + "\r\n"; } 
m_listener.Stop(); 
}

Upvotes: 0

Views: 1222

Answers (1)

Jonathan Henson
Jonathan Henson

Reputation: 8206

HttpListener is probably not your best bet if you want to do a full network scan. I would look into the System.Net.Sockets namespace. Port scanners are typically done via the sockets interface. You can create TCP and UDP sockets and bind them to listen to any port on a local machine or connect to a remote machine. If the socket succeeds, then the port is open and ready.

Upvotes: 2

Related Questions