1

I need to find whether a port Ex. port 8080 is opened on a Linux system. I'm looking for a C or C++ API call that will return true or false or the equivalent when given a port number. This only needs to run locally. I don't want to know if there is a process listening on the port, only that is not blocked by the firewall.

I want to do the equivalent of

 if( ! IsPortOpen(8080))
     cout << "please request IT to open port 8080 before running this tool";
     exit(1);
 }
Mark Lakata
  • 19,008
  • 5
  • 97
  • 119
VamsiKrishna
  • 641
  • 6
  • 14
  • 26

1 Answers1

6

I assume you are looking for open ports on the local machine. There are a lot of tools to do this.

One of the easier to use and understand is

lsof -i

For remote machines, try nmapor even easier and more basic netcat. For example

netcat targetHost 8080

0x90
  • 5,889
  • 2
  • 33
  • 52