Bye Bye Moore

PoCソルジャーな零細事業主が作業メモを残すブログ

空いてるポートを確認するnmapというコマンド

nmapは空いてるポートを確認できる便利コマンドです。
自分の環境はもとより、他所のサイトのポートも確認できます。

導入(OS X

基本brewでいけます……が、xdodebulidの権限を設定してないと
以下のようなメッセージを吐いて怒られます。

$ brew install nmap
Warning: You have not agreed to the Xcode license.
Builds will fail! Agree to the license by opening Xcode.app or running:
    sudo xcodebuild -license

指示通り

$ sudo xcodebuild -license

とやってライセンスを表示した上で、同意できるあらagreeと入力をしてください。
あとはいつも通り。

$ brew install nmap

ただし、

(ry
==> Caveats
Python modules have been installed and Homebrew's site-packages is not
in your Python sys.path, so you will not be able to import the modules
this formula installed. If you plan to develop with these modules,
please run:
  mkdir -p /Users/shuzo_kino/.local/lib/python3.4/site-packages
  echo 'import site; site.addsitedir("/usr/local/lib/python2.7/site-packages")' >> /Users/shuzo_kino/.local/lib/python3.4/site-packages/homebrew.pth

とあるように、一部Python系パッケージが必要な場合、ちゃんとパスを通してあげた上で再ビルドする必要が有ります、

実際の所

基本的な使い方は

$ nmap -v localhost

Starting Nmap 6.47 ( http://nmap.org ) at 2015-10-16 23:42 JST
Initiating Ping Scan at 23:42
Scanning localhost (127.0.0.1) [2 ports]
Completed Ping Scan at 23:42, 0.00s elapsed (1 total hosts)
Initiating Connect Scan at 23:42
Scanning localhost (127.0.0.1) [1000 ports]
Discovered open port 80/tcp on 127.0.0.1
Discovered open port 631/tcp on 127.0.0.1
Completed Connect Scan at 23:42, 5.58s elapsed (1000 total ports)
Nmap scan report for localhost (127.0.0.1)
Host is up (0.00045s latency).
Not shown: 969 closed ports, 29 filtered ports
PORT    STATE SERVICE
80/tcp  open  http
631/tcp open  ipp

Read data files from: /usr/local/bin/../share/nmap
Nmap done: 1 IP address (1 host up) scanned in 5.63 seconds

また、ログから起こすことも可能です
よって、以下のような使い方もできます。

        tail -f access_log |
            awk '/myhome.html/ { system("nmap " $1 ">> logdir/myhome.html") }'

詳しい使い方を知りたい場合、マニュアルは次のページにあります。
オプションがGitばりに豊富です。
Chapter 15. Nmap Reference Guide