Nmap 是一個開放原始碼的網路掃描與探測工具,可以讓網路管理者掃描整個子網域或主機的連接埠等,功能非常強大。

Nmap(Network Mapper)是一個開放原始碼的網路檢測工具,它的功能非常強大,這裡整理了許多使用範例,讓初學者可以快速上手。

 

安裝

一般的 Linux 系統通常都會將 Nmap 納入官方的套件庫,如果是 Red Hat 系列的 Linux,可以使用 yum 安裝:

sudo yum install nmap

而如果是 Debian 系列的 Linux 則可使用 apt:

sudo apt-get install nmap
 

基本主機掃描

Nmap 最基本的用法就是掃描主機是否有開機,並且開啟哪些連接埠:

nmap www.hinet.net

輸出為

Starting Nmap 6.40 ( http://nmap.org ) at 2014-10-02 08:09 CST
Nmap scan report for www.hinet.net (202.39.253.11)
Host is up (0.0034s latency).
rDNS record for 202.39.253.11: 202-39-253-11.HINET-IP.hinet.net
Not shown: 998 filtered ports
PORT STATE SERVICE
80/tcp open http
113/tcp closed ident
Nmap done: 1 IP address (1 host up) scanned in 6.05 seconds

也可以直接使用 IP 位址來指定掃描的主機:

nmap 202.39.253.11

如果加上 -v 參數,會有更詳細的輸出:

nmap -v www.hinet.net

輸出為

Starting Nmap 6.40 ( http://nmap.org ) at 2014-10-02 08:32 CST
Initiating Ping Scan at 08:32
Scanning www.hinet.net (202.39.253.11) [2 ports]
Completed Ping Scan at 08:32, 1.20s elapsed (1 total hosts)
Initiating Parallel DNS resolution of 1 host. at 08:32
Completed Parallel DNS resolution of 1 host. at 08:32, 0.00s elapsed
Initiating Connect Scan at 08:32
Scanning www.hinet.net (202.39.253.11) [1000 ports]
Discovered open port 80/tcp on 202.39.253.11
Completed Connect Scan at 08:32, 4.81s elapsed (1000 total ports)
Nmap scan report for www.hinet.net (202.39.253.11)
Host is up (0.0044s latency).
rDNS record for 202.39.253.11: 202-39-253-11.HINET-IP.hinet.net
Not shown: 998 filtered ports
PORT STATE SERVICE
80/tcp open http
113/tcp closed ident Read data files from: /usr/bin/../share/nmap
Nmap done: 1 IP address (1 host up) scanned in 6.13 seconds
 

掃描多台主機

如果要一次掃描多台主機,就直接把所有的主機名稱都放進 nmap 的參數中即可:

nmap www.hinet.net tw.yahoo.com www.google.com.tw

輸出為

Starting Nmap 6.40 ( http://nmap.org ) at 2014-10-02 08:36 CST
Nmap scan report for www.hinet.net (202.39.253.11)
Host is up (0.0038s latency).
rDNS record for 202.39.253.11: 202-39-253-11.HINET-IP.hinet.net
Not shown: 998 filtered ports
PORT STATE SERVICE
80/tcp open http
113/tcp closed ident Nmap scan report for tw.yahoo.com (202.43.192.109)
Host is up (0.0046s latency).
rDNS record for 202.43.192.109: ir1.fp.vip.tw1.yahoo.com
Not shown: 997 filtered ports
PORT STATE SERVICE
80/tcp open http
113/tcp closed ident
443/tcp open https Nmap scan report for www.google.com.tw (74.125.31.94)
Host is up (0.011s latency).
rDNS record for 74.125.31.94: tb-in-f94.1e100.net
Not shown: 997 filtered ports
PORT STATE SERVICE
80/tcp open http
113/tcp closed ident
443/tcp open https Nmap done: 3 IP addresses (3 hosts up) scanned in 9.97 seconds

您也可以直接使用萬用字元,一次掃描整個子網域:

nmap 192.168.0.*

或是

nmap 192.168.0.0/24

如果您想要掃描 192.168.0.123192.168.0.124192.168.0.125 這三台主機,可以寫成這樣:

nmap 192.168.0.123,124,125

如果要掃描子網域中連續的某一段,可以這樣寫:

nmap 192.168.0.123-140
 

以檔案列表指定主機

nmap 也可以直接從檔案讀取要掃描的主機,假設我們有一個主機列表檔案 hostlist.txt,其內容為:

www.hinet.net
192.168.0.123
www.google.com.tw

然後我們就可以使用 nmap 直接讀取這個檔案內容來進行掃描:

nmap -iL hostlist.txt
 

排除指定的主機

如果要掃描整個網域,但是要排除某些機器,可以使用 --exclude 參數:

nmap 192.168.0.* --exclude 192.168.0.100

若以檔案方式指定主機,也可以使用 --excludefile 指定排除的列表:

nmap -iL hostlist.txt --excludefile excludelist.txt

偵測作業系統版本

如果要偵測主機的作業系統與各種服務的版本,可以加上 -A 參數:

nmap -A scanme.nmap.org

輸出為

Starting Nmap 6.40 ( http://nmap.org ) at 2014-10-02 09:37 CST
Nmap scan report for scanme.nmap.org (74.207.244.221)
Host is up (0.14s latency).
Not shown: 990 closed ports
PORT STATE SERVICE VERSION
22/tcp open ssh OpenSSH 5.3p1 Debian 3ubuntu7.11
(Ubuntu Linux; protocol 2.0)
| ssh-hostkey: 1024 8d:60:f1:7c:ca:b7:3d:0a:d6:67:54:9d:69:d9:b9:dd (DSA)
|_2048 79:f8:09:ac:d4:e2:32:42:10:49:d3:bd:20:82:85:ec (RSA)
53/tcp filtered domain
80/tcp open http Apache httpd 2.2.142
((Ubuntu))
|_http-title: Go ahead and ScanMe!
139/tcp filtered netbios-ssn
445/tcp filtered microsoft-ds
6666/tcp filtered irc
6667/tcp filtered irc
6668/tcp filtered irc
6669/tcp filtered irc
9929/tcp open nping-echo Nping echo
Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel3
Service detection performed. Please report any incorrect results at http://nmap.org/submit/ .
Nmap done: 1 IP address (1 host up) scanned in 58.98 seconds

1SSH 伺服器版本。

2Apache 伺服器版本。

3作業系統類型。

如果只需要作業系統資訊,可以使用 -O 參數:

nmap -O scanme.nmap.org

輸出為

Starting Nmap 6.40 ( http://nmap.org ) at 2014-10-02 09:44 CST
Nmap scan report for scanme.nmap.org (74.207.244.221)
Host is up (0.14s latency).
Not shown: 990 closed ports
PORT STATE SERVICE
22/tcp open ssh
53/tcp filtered domain
80/tcp open http
139/tcp filtered netbios-ssn
445/tcp filtered microsoft-ds
6666/tcp filtered irc
6667/tcp filtered irc
6668/tcp filtered irc
6669/tcp filtered irc
9929/tcp open nping-echo
Aggressive OS guesses: Linux 2.6.32 - 3.9 (98%), Linux 2.6.38 - 3.0 (97%), Linux 2.6.32 - 2.6.39 (97%), Netgear DG834G WAP or Western Digital WD TV media player (96%), Linux 2.6.32 - 3.2 (95%), Linux 3.0 - 3.9 (95%), Linux 3.2 (95%), Linux 2.6.32 - 3.6 (95%), Linux 3.1 (95%), AXIS 210A or 211 Network Camera (Linux 2.6) (94%)
No exact OS matches for host (test conditions non-ideal).
Network Distance: 12 hops OS detection performed. Please report any incorrect results at http://nmap.org/submit/ .
Nmap done: 1 IP address (1 host up) scanned in 18.80 seconds

若只需要各種服務的版本:

nmap -sV scanme.nmap.org

輸出為

Starting Nmap 6.40 ( http://nmap.org ) at 2014-10-02 13:16 CST
Nmap scan report for scanme.nmap.org (74.207.244.221)
Host is up (0.14s latency).
Not shown: 989 closed ports
PORT STATE SERVICE VERSION
22/tcp open ssh OpenSSH 5.3p1 Debian 3ubuntu7.1 (Ubuntu Linux; protocol 2.0)
53/tcp filtered domain
80/tcp open http Apache httpd 2.2.14 ((Ubuntu))
139/tcp filtered netbios-ssn
445/tcp filtered microsoft-ds
1105/tcp filtered ftranhc
6666/tcp filtered irc
6667/tcp filtered irc
6668/tcp filtered irc
6669/tcp filtered irc
9929/tcp open nping-echo Nping echo
Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel Service detection performed. Please report any incorrect results at http://nmap.org/submit/ .
Nmap done: 1 IP address (1 host up) scanned in 48.03 seconds

測試主機是否有防火牆

Nmap 可以透過 TCP ACK 掃描,偵測主機是否有啟用防火牆:

nmap -sA scanme.nmap.org

輸出為

Starting Nmap 6.40 ( http://nmap.org ) at 2014-10-02 10:17 CST
Nmap scan report for scanme.nmap.org (74.207.244.221)
Host is up (0.14s latency).
All 1000 scanned ports on scanme.nmap.org (74.207.244.221) are unfiltered Nmap done: 1 IP address (1 host up) scanned in 2.22 seconds

掃描有防火牆的主機

掃描在防火牆保護下的主機:

nmap -PN scanme.nmap.org

輸出為

Starting Nmap 6.40 ( http://nmap.org ) at 2014-10-02 10:24 CST
Nmap scan report for scanme.nmap.org (74.207.244.221)
Host is up (0.14s latency).
Not shown: 990 closed ports
PORT STATE SERVICE
22/tcp open ssh
53/tcp filtered domain
80/tcp open http
139/tcp filtered netbios-ssn
445/tcp filtered microsoft-ds
6666/tcp filtered irc
6667/tcp filtered irc
6668/tcp filtered irc
6669/tcp filtered irc
9929/tcp open nping-echo Nmap done: 1 IP address (1 host up) scanned in 16.99 seconds

偵測有開機的主機

掃描整個網路,偵測所有有開機的主機(ping scan):

nmap -sP 140.115.35.0/24

輸出為

Starting Nmap 6.40 ( http://nmap.org ) at 2014-10-02 11:06 CST
Nmap scan report for mail.atm.ncu.edu.tw (140.115.35.1)
Host is up (0.0018s latency).
Nmap scan report for rain.atm.ncu.edu.tw (140.115.35.4)
Host is up (0.0015s latency).
Nmap scan report for iut.atm.ncu.edu.tw (140.115.35.5)
Host is up (0.0017s latency).
[略]
Nmap scan report for 140.115.35.254
Host is up (0.0047s latency).
Nmap done: 256 IP addresses (117 hosts up) scanned in 3.00 seconds

快速掃描

加快掃描的速度:

nmap -F www.hinet.net

輸出為

Starting Nmap 6.40 ( http://nmap.org ) at 2014-10-02 10:55 CST
Nmap scan report for www.hinet.net (202.39.253.11)
Host is up (0.0034s latency).
rDNS record for 202.39.253.11: 202-39-253-11.HINET-IP.hinet.net
Not shown: 98 filtered ports
PORT STATE SERVICE
80/tcp open http
113/tcp closed ident Nmap done: 1 IP address (1 host up) scanned in 2.19 seconds

另一種方式:

nmap -T5 192.168.1.0/24

指定掃描的連接埠

掃描連接埠 80

nmap -p 80 192.168.1.1

指定 TCP 連接埠 80

nmap -p T:80 192.168.1.1

指定 UDP 連接埠 53

nmap -p U:53 192.168.1.1

掃描兩個連接埠:

nmap -p 80,443 192.168.1.1

指定連接埠範圍:

nmap -p 80-200 192.168.1.1

結合各種參數:

nmap -p U:53,111,137,T:21-25,80,139,8080 192.168.1.1
nmap -p U:53,111,137,T:21-25,80,139,8080 server1.cyberciti.biz
nmap -v -sU -sT -p U:53,111,137,T:21-25,80,139,8080 192.168.1.254

掃描前 10 個常用的連接埠:

nmap --top-ports 10 192.168.1.1

查詢主機名稱

只查詢網域中所有的主機名稱,不做任何主機與連接埠的偵測:

nmap -sL 192.168.1.0/24

Nmap 網路診斷工具基本使用技巧與教學的更多相关文章

  1. 第五章、 Linux 常用網路指令

    http://linux.vbird.org/linux_server/0140networkcommand.php     第五章. Linux 常用網路指令 切換解析度為 800x600 最近更新 ...

  2. 新購電腦筆記 - G1.Sniper B7 內建網路晶片在 Mint 17.2(Cinnamon)上無法使用(已解決)

    又好久沒寫文章了,這次因新購電腦,有一些狀況,故做一下記錄,也分享給遇到同樣問題的格友 以前在公司裝 Ubuntu 從沒遇過這麼多問題,這次自己第一次組電腦,也第一次裝 Mint,問題倒是不少 第一個 ...

  3. Iptables網路連線限制及攻擊防護和相關設定

    [筆記整理]Iptables網路連線限制及攻擊防護和相關設定 1. 限制每個IP連接HTTP最大併發50個連接數 iptables -A INPUT -p tcp --dport 80 -m conn ...

  4. oracle系統表、數據字典介紹與日常問題診斷

    oracle系統表.數據字典介紹與日常問題診斷 數據字典是由唯讀的table和view組成的,產生於$oracle_home\rdbms\admin\catalog.sql.裡面儲存Oracle資料庫 ...

  5. NB實體連線到公司的網路,無法上網解決方案,需設 proxy。

    未使用 VPN Cisco Anyconnect 已連線到公司的網路: google-chrome-stable --proxy-server="proxy.XXXcomm.com:3128 ...

  6. [Xamarin] 透過WebClient跟網路取得資料 (转帖)

    之前寫過一篇文章,關於在Android上面取得資料 透過GET方式傳資料給Server(含解決中文編碼問題) 我們來回顧一下 Android 端的Code: 有沒有超多,如果是在Xaramin下面,真 ...

  7. 使用 WebClient 來存取 GET,POST,PUT,DELETE,PATCH 網路資源

    WebClient 基本資訊 提供通用方法使用 WebRequest 類別傳送及接收 URI (支援 http:, https:, ftp:,和 file: ) 的資源 Namespace:Syste ...

  8. Nmap——主机、端口扫描工具

    nmap 其基本功能有三个,一是探测一组主机是否在线:其次是扫描主机端口,嗅探所提供的网络服务:还可以推断主机所用的操作系统 . 这是百度给的介绍:http://baike.baidu.com/lin ...

  9. PostgreSQL 图形化客户端工具的使用技巧你都get了吗?

    PostgreSQL 数据库作为目前功能较强大的开源数据库,得到了广泛应用.其中,TSA就用到了这款数据库来存储处理后的一些业务数据.虽然PostgreSQL自身提供了命令行交互式客户端工具psql, ...

随机推荐

  1. !cocos2d ccdictionary->retain()的问题

    我再a类当中生命了一个dict,将它带入到b类当中,但没有在b类初始化时retain,于是在update当中找不到了.啃爹不.记得retain()

  2. BZOJ3832 : [Poi2014]Rally

    f[0][i]为i出发的最长路,f[1][i]为到i的最长路 新建源汇S,T,S向每个点连边,每个点向T连边 将所有点划分为两个集合S与T,一开始S中只有S,其它点都在T中 用一棵线段树维护所有连接属 ...

  3. 【COGS & USACO Training】710. 命名那个数字(hash+水题+dfs)

    http://cojs.tk/cogs/problem/problem.php?pid=710 近日开始刷水... 此题我为了练一下hash...但是hash跑得比暴力还慢.. 不言而喻... #in ...

  4. 使用Spring的注解方式实现AOP

    Spring对AOP的实现提供了很好的支持.下面我们就使用Spring的注解来完成AOP做一个例子. 首先,为了使用Spring的AOP注解功能,必须导入如下几个包.aspectjrt.jar,asp ...

  5. JAVA中使用FTPClient实现文件上传下载

    在JAVA程序中,经常需要和FTP打交道,比如向FTP服务器上传文件.下载文件,本文简单介绍如何利用jakarta commons中的FTPClient(在commons-net包中)实现上传下载文件 ...

  6. SSH整合配置二级缓存

    一.了解 Hibernate的session提供了一级缓存,每个session,对同一个id进行两次load,不会发送两条sql给数据库,但session关闭时,一级缓存失效. 二级缓存是Sessio ...

  7. C Memory Layout C语言中的内存布局

    在C语言中,内存的主要分为下列几部分: 1. Text/Code Segment 文本/代码区 2. Initialized Data Segments 初始化的数据区 3. Uninitialize ...

  8. [译]- 6-1 排列窗体上的控件(Laying Out Widgets on a Form)

     排列窗体上的控件(Laying Out Widgets on a Form) 中英文对照:form(窗体),layout(布局或者排列,意思是进行窗体上控件的排列的过程,如大小位置等) absolu ...

  9. IIS7 Appcmd.exe 使用

    如果您运行的是 64 位 Windows,请从 %windir%\system32\inetsrv 目录而不是 %windir%\syswow64\inetsrv 目录中使用 Appcmd.exe. ...

  10. 清橙 A1206 小Z的袜子(莫队算法)

    A1206. 小Z的袜子 时间限制:1.0s   内存限制:512.0MB   总提交次数:1357   AC次数:406   平均分:46.75   将本题分享到:        查看未格式化的试题 ...