Focus Windows port scanning with the netscan command

How to use the netscan command to focus Windows port scanning.

When security scanners (or hackers) look for vulnerable ports on Windows PCs and other computers, they'll often perform port scans. These may target only well-known ports, or those for which vulnerabilities exist, or may work their way through the entire range of valid UDP and TCP port addresses (0 through 65,535, which tells those with "binary sophistication" that port addresses are 16 bits in length).

System or network admins seeking to foil such scans, or to check port status on exposed machines, can get quick, accurate help from the Windows command line utility named netstat (for great detail on this utility, see the Windows netstat reference page online). Use the command netstat –an to produce a listing of TCP and UDP ports that have been used or are active or in "listening" status on a Windows computer (this command works with all modern Windows versions, the listing that follows came from a Windows XP machine, with SP2 and all current security updates, patches, and fixes installed).

Listing 1: Typical netstat –an output

 C:\>netstat -an Active Connections Proto Local Address Foreign Address State TCP LISTENING TCP LISTENING TCP LISTENING TCP LISTENING TCP LISTENING TCP LISTENING TCP ESTABLISHED TCP ESTABLISHED UDP *:* UDP *:* UDP *:* UDP *:* UDP *:* UDP *:* UDP *:* UDP *:* UDP *:* UDP *:* UDP *:* UDP *:* UDP *:* UDP *:* UDP *:*

If a port is in the LISTENING state this means the PC is waiting for an incoming connection on that port. If it's in the ESTABLISHED state, there's an active connection on that port up and running. But even for UDP (which doesn't carry state information), all recently accessed port numbers will show up in this output.

Why does this matter? Because it provides a complete and succinct list of all the ports this computer has used since the last time it booted up. This means you need check only these ports externally to make sure they're not open to any and all comers (or scanners) to see if that machine is secure or otherwise. You can use the custom port probe available through Steve Gibson's "Shields UP!" facility at http://grc.com to check these ports quicky and easily. Here's how:

  • look for and click the Shields UP! Link on his home page
  • click Shields UP again
  • click Proceed
  • click "User Specified Custom Port Probe" on the resulting page
  • enter all the port numbers that show up in the netscan output

(Note: port addresses show up to the right of the colons following the IP addresses for both TCP and UDP ports, as shown in Listing 1). This provides a quick way to see if any are open to outside scanners.

This technique works well for pretty much all Windows machines from Windows 95 to the latest releases. Use it to help drive your security scans, and you'll be well-equipped to keep scanners at bay.

Ed Tittel is a full-time freelance writer, trainer, and consultant who specializes in matters related to information security, markup languages, and networking technologies. He's a regular contributor to numerous TechTarget Web sites, technology editor for Certification Magazine, and writes an e-mail newsletter for CramSession called "Must Know News."

Dig Deeper on Network infrastructure

Unified Communications
Mobile Computing
Data Center