Note: Only utilize a port scanner on sites you have permission to test. Also, note the legalities of port scanners in your territories.
Update 8/13/17: I made a few modifications to the code. Namely:
- some software answers on a port but doesn’t respond and isn’t closed causing a hang. I put a timeout on the read action
- I used 4 go routines to add concurrency.
- I removed the bufio ReadString methods in place of raw bytes read in the buffer using this users methodology: https://gist.github.com/kenshinx/5796276 It improved the performance from 8000 ports scaned in over a min, to under 20 seconds!
As I’m learning the Go language, I thought I’d work on a small project of making a utility I wrote in Python, in the Go language. In this case, I chose a port scanner I wrote in Python. The scanner tries to interrogate ports and return any banner that would indicate what’s installed there.
The original code I wrote in Python utilized the socket and sys libraries. I wrote it while taking an InfoSec course over at Offensive Security. Anyway… years later, I’m thinking of a project to try and do in Go (just go kick the tires and get used to the code) and I figure I might as well port that project into Go.
Go Port Scanner
The code is simple it basically kicks off a shell prompt asking for a host, then a starting port and an ending port. It then iterates over the port range, trying each port in turn.
Here’s the code (link):