6

I'm trying to get Cygwin to show what ports my laptop has open but when I try to run it, it says the command isn't found.

This is the command I'm trying: nmap -v -A <<IP address>>

Steve Chambers
  • 37,270
  • 24
  • 156
  • 208
Adam Dewhurst
  • 91
  • 1
  • 1
  • 7
  • Cygwin doesn't provide nmap. Have you [installed nmap for Windows](https://nmap.org/book/inst-windows.html)? – pak Feb 26 '16 at 18:25
  • yes I did install it for nmap but i thought it would run the same way you run it the same way I ran it through terminal on ubuntu but how wrong was I , do you know what command is used to run it on cygwin? – Adam Dewhurst Mar 01 '16 at 13:49
  • You need to install it somewhere in your path, or add the installation directory to Cygwin's path, so that Cygwin knows where to look for it. You can do that by adding `export PATH=$PATH:` to your `.bash_profile`. – pak Mar 01 '16 at 16:16

2 Answers2

9

This blog post has some useful info about how to get this working. Have copied it below in case it ever goes away:

  1. Download nmap
  2. Install nmap “self-installer” .exe and install Npcap when asked by the Nmap installer.
  3. Note: An alternative of adding the path to the ~/.bashrc file is suggested in the comments. Cygwin: add to ~/.bash_profile: alias nmap="/cygdrive/c/Program\ Files\ \(x86\)/Nmap/nmap.exe". Note the \ and \( are vital for Cygwin shell to interpret the command correctly.
  4. Open a new Cygwin window to start using nmap
Steve Chambers
  • 37,270
  • 24
  • 156
  • 208
  • 1
    Why not just edit `~/.bashrc` and add it to the `$PATH`? `export PATH=$PATH:'/cygdrive/c/Program Files (x86)/Nmap'` – AJM Apr 30 '21 at 16:41
  • 2
    Yes that seems simpler - the instructions are just mirroring the blog post and it will work either way so have added a note about this. – Steve Chambers May 01 '21 at 08:28
4

Depending on where you installed nmap to, it will be something like /cygdrive/c/Program Files (x86)/Nmap/nmap. In the Windows command prompt (cmd), it will be c:\Program Files (x86)\Nmap\nmap.

However, nmap isn't the best tool to discover listening ports in Linux and won't work at all in Windows. In cygwin, try this: netstat -ano|grep LISTEN. In the Windows command prompt: netstat -ano|find "LISTEN". In Linux: netstat -anp|grep LISTEN.

SArcher
  • 264
  • 1
  • 9
  • 1
    `nmap` and `netstat` (or newer `ss` on Linux systems) are for very different tasks. --- **`nmap`** will actually probe if the systems responds on the tested ports (or other protocols like ICMP) it is mainly being used to check remote systems and the communication path. --- **`netstat`** (or `ss`) will list sockets on the system where you run the command. It cannot be used to test remote systems, the communication path or how the system responds to various probes. – pabouk - Ukraine stay strong Jul 02 '21 at 08:04