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. BZOJ1707 : [Usaco2007 Nov]tanning分配防晒霜

    S向每头奶牛连边,容量1 每个防晒霜向T连边,容量cover 每头奶牛向SPF在自己范围内的防晒霜连边,容量inf 用线段树优化建图跑最大流即可. #include<cstdio> con ...

  2. BZOJ3831 : [Poi2014]Little Bird

    设f[i]表示到i最少休息次数,f[i]=min(f[j]+(h[j]<=a[i])),i-k<=j<i,单调队列优化DP #include<cstdio> #defin ...

  3. HDU 2653 (记忆化BFS搜索+优先队列)

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=2653 题目大意:迷宫中有普通点和陷阱.其中普通点可以走可以飞,但是陷阱只能飞.走耗时1,飞耗时2.但 ...

  4. TYVJ P1094 矩形分割 标签:DP

    做题记录:2016-08-12 21:42:21 背景 YHOI Train#4 Problem 1 描述 出于某些方面的需求,我们要把一块N×M的木板切成一个个1×1的小方块.对于一块木板,我们只能 ...

  5. 【BZOJ】1191: [HNOI2006]超级英雄Hero(二分图匹配)

    http://www.lydsy.com/JudgeOnline/problem.php?id=1191 一眼题,笑嘻嘻地写了匈牙利,提交..WA了?不科学!!!!!数组小了??不思考了,改大提交,. ...

  6. ECMAScript继承

    继承的定义 ECMAScript 实现继承可以从父类入手,所有开发者定义的类都可作为父类,出于安全考虑,本地类和宿主类不能作为父类,因为容易收到恶意攻击 创建只是用于给子类提供通用函数的父类被看作抽象 ...

  7. 用javascript协助导入图片

    用javascript协助导入图片 需求 先说说需求.春节回家见爸妈,老爸迷上了摄影.他把平时的照片都上传到了 成都图片网, 这个成都图片网专门有一个 "快拍成都" 的版块,用于大 ...

  8. NSMakeRange,substringWithRange,substringToIndex,substringFromIndex区别和联系

      typedef NSRange *NSRangePointer; NS_INLINE NSRange NSMakeRange(NSUInteger loc, NSUInteger len) {   ...

  9. [转载]git 忽略某些文件

    项目中经常会生成一些Git系统不需要追踪(track)的文件.典型的是在编译生成过程中 产生的文件或是编程器生成的临时备份文件.当然,你不追踪(track)这些文件,可以 平时不用"git ...

  10. mysql安装后的配置

    mysql的安装其实就是一步一步按提示就可以: 1.开始安装 2.选择mysql安装位置 3.选择数据库存放位置,最好和mysql安装在一起,好查找 4.选择详细设置 5.选开发者机器 6.选多功能型 ...