• Post Reply Bookmark Topic Watch Topic
  • New Topic

Port scanning Vista

 
Nikolay Tsonkov
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

I have implemented a port scanner in Java which has to check if certain ports are occupied. I am using a standard approach by creating a socket with each port and if there is no exception the port is available and if an exception is thrown it would indicate that the port is occupied.


The problem is that sometimes it shows that some ports are not available. After checking with netstat -a the list doesn't show the occupied ports. I have checked with various scanner tools it still don't show them. That issue occurs mostly on Windows Vista and Windows Server 2008. If anyone knows what the problem might be or any other approach to scan ports on a system with Java I will really appreciate it.
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24213
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Note that a port scanner normally runs on a system other than the one being scanned, and uses a Socket to attempt to connect to a service running on that system. That will tell you which ports have something listening on them. Trying to open a ServerSocket tells you completely different information: which ports you're allowed to listen on, for any number of reasons.

Now, without having much special knowledge of those operating systems, I can tell you that some OSs -- notably UNIX-like systems -- restrict which ports a user process can open a ServerSocket on. In general, without special permissions, your program running on a Linux system would report that ports 1-1024 were all "taken", when in fact most of them are free. That's because ordinary user processes aren't allowed to listen on any of those ports.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!