ZiBaT => Peter
Levinsky => Tech => exercise |
Port Scanner |
Updated : 2021-11-18
|
The purpose of this exercise is to be able to scan open ports on a host.
This could be done as either a White-Hat attack, or a Black-Hat attack. What is the difference?
You should only scan for open TCP ports, not UDP.
Why is it more difficult to scan UDP ports?
Create a new console application project.
Either hardcode a destination or ask the user for an IP-address. (First time could just be localhost / 127.0.0.1)
Implement a for loop that goes through all available ports (How many? Hint: 16bit).
For each port, create a TcpClient with the IP-address and the port number.
If it throws an Exception, the port is not in use.
If it doesn’t throw an Exception, remember the port number (in a list?)
Show the open ports in the console.
Now the speed of your port scanner is probably not very impressive.
Why is it so slow?
One way to make it faster is to use threads.
How would you implement this? One thread per port, or multiple ports per thread?
How will you show the open ports in the console when using threads?
If testing on your local PC, there is a much faster way of testing if a port is already in use.
How would you check this?
Hint: Can the same port be used twice?
Until now you have scanned for tcp-ports. If you are on localhost you can also scan for UDP Ports.
Make a new project to scan for UDP-ports
Can you think of other ways to improve the Port Scanner (tcp)?