2

Is it possible to find specific port using command prompt? I want to use the exec command in php to check if a port is open. The fsockopen function in php is very slow so i wanna try to use the cmd to check the port and see if that works better. I want to find if port 7878 is open.

I do not wish to download any softwares, I only want to know if it's possible to do it directly in cmd. And if its possible i want to know how the command for it

Tim Levinsson
  • 597
  • 2
  • 7
  • 20

2 Answers2

2

i do not know about php code but in network we using : cmd->telnet [domainname or ip] [port]

i strogly recomended not to use exec in php and evenlook here

so i found this hope help you

here (may be slower but safer)

Community
  • 1
  • 1
hamid
  • 31
  • 7
1

You can use netstat:

netstat -na | find ":< port number >"

To find a foreign port you could use:

netstat -an | findstr ":N[^:]*$"

To find a local port you might use:

netstat -an | findstr ":N.*:[^:]*$"
Samuel
  • 3,631
  • 5
  • 37
  • 71
  • Thanks. But that returns like 100 rows. If i use exec in php to echo this it will display all these rows on the page so it would be better if it would return "Open/Closed" or "Online/Offline" or "0/1" or something like that – Tim Levinsson May 16 '16 at 01:07
  • @user3055512 Updated. Prepend ":" before port number to narrow your search results – Samuel May 16 '16 at 01:12