包包網(wǎng)站建設(shè)策劃書seo搜索優(yōu)化專員招聘
【Linux】獲得同一子網(wǎng)下當(dāng)前在線設(shè)備IP/Latency/MAC 通過nmap指定CIDR掃描當(dāng)前在線設(shè)備
通過路由器的后臺(tái),查看當(dāng)前在線設(shè)備,受到網(wǎng)卡版本的影響,有時(shí)會(huì)有部分設(shè)備看不見MAC和分配的IP。此時(shí),可以借助命令行工具掃描子網(wǎng)下所有連接的設(shè)備信息與通信狀態(tài)。
Nmap 是一個(gè)強(qiáng)大的網(wǎng)絡(luò)掃描工具,提供了豐富的功能,用于發(fā)現(xiàn)網(wǎng)絡(luò)中的主機(jī)、服務(wù)、操作系統(tǒng)、版本、漏洞等信息。
安裝方法
sudo apt-get update
sudo apt-get install nmap
查看幫助
nmap
Nmap 7.80 ( https://nmap.org )
Usage: nmap [Scan Type(s)] [Options] {target specification}
TARGET SPECIFICATION:Can pass hostnames, IP addresses, networks, etc.Ex: scanme.nmap.org, microsoft.com/24, 192.168.0.1; 10.0.0-255.1-254-iL <inputfilename>: Input from list of hosts/networks-iR <num hosts>: Choose random targets--exclude <host1[,host2][,host3],...>: Exclude hosts/networks--excludefile <exclude_file>: Exclude list from file
HOST DISCOVERY:-sL: List Scan - simply list targets to scan-sn: Ping Scan - disable port scan-Pn: Treat all hosts as online -- skip host discovery-PS/PA/PU/PY[portlist]: TCP SYN/ACK, UDP or SCTP discovery to given ports-PE/PP/PM: ICMP echo, timestamp, and netmask request discovery probes-PO[protocol list]: IP Protocol Ping-n/-R: Never do DNS resolution/Always resolve [default: sometimes]--dns-servers <serv1[,serv2],...>: Specify custom DNS servers--system-dns: Use OS's DNS resolver--traceroute: Trace hop path to each host
SCAN TECHNIQUES:-sS/sT/sA/sW/sM: TCP SYN/Connect()/ACK/Window/Maimon scans-sU: UDP Scan-sN/sF/sX: TCP Null, FIN, and Xmas scans--scanflags <flags>: Customize TCP scan flags-sI <zombie host[:probeport]>: Idle scan-sY/sZ: SCTP INIT/COOKIE-ECHO scans-sO: IP protocol scan-b <FTP relay host>: FTP bounce scan
PORT SPECIFICATION AND SCAN ORDER:-p <port ranges>: Only scan specified portsEx: -p22; -p1-65535; -p U:53,111,137,T:21-25,80,139,8080,S:9--exclude-ports <port ranges>: Exclude the specified ports from scanning-F: Fast mode - Scan fewer ports than the default scan-r: Scan ports consecutively - don't randomize--top-ports <number>: Scan <number> most common ports--port-ratio <ratio>: Scan ports more common than <ratio>
SERVICE/VERSION DETECTION:-sV: Probe open ports to determine service/version info--version-intensity <level>: Set from 0 (light) to 9 (try all probes)--version-light: Limit to most likely probes (intensity 2)--version-all: Try every single probe (intensity 9)--version-trace: Show detailed version scan activity (for debugging)
SCRIPT SCAN:-sC: equivalent to --script=default--script=<Lua scripts>: <Lua scripts> is a comma separated list ofdirectories, script-files or script-categories--script-args=<n1=v1,[n2=v2,...]>: provide arguments to scripts--script-args-file=filename: provide NSE script args in a file--script-trace: Show all data sent and received--script-updatedb: Update the script database.--script-help=<Lua scripts>: Show help about scripts.<Lua scripts> is a comma-separated list of script-files orscript-categories.
OS DETECTION:-O: Enable OS detection--osscan-limit: Limit OS detection to promising targets--osscan-guess: Guess OS more aggressively
TIMING AND PERFORMANCE:Options which take <time> are in seconds, or append 'ms' (milliseconds),'s' (seconds), 'm' (minutes), or 'h' (hours) to the value (e.g. 30m).-T<0-5>: Set timing template (higher is faster)--min-hostgroup/max-hostgroup <size>: Parallel host scan group sizes--min-parallelism/max-parallelism <numprobes>: Probe parallelization--min-rtt-timeout/max-rtt-timeout/initial-rtt-timeout <time>: Specifiesprobe round trip time.--max-retries <tries>: Caps number of port scan probe retransmissions.--host-timeout <time>: Give up on target after this long--scan-delay/--max-scan-delay <time>: Adjust delay between probes--min-rate <number>: Send packets no slower than <number> per second--max-rate <number>: Send packets no faster than <number> per second
FIREWALL/IDS EVASION AND SPOOFING:-f; --mtu <val>: fragment packets (optionally w/given MTU)-D <decoy1,decoy2[,ME],...>: Cloak a scan with decoys-S <IP_Address>: Spoof source address-e <iface>: Use specified interface-g/--source-port <portnum>: Use given port number--proxies <url1,[url2],...>: Relay connections through HTTP/SOCKS4 proxies--data <hex string>: Append a custom payload to sent packets--data-string <string>: Append a custom ASCII string to sent packets--data-length <num>: Append random data to sent packets--ip-options <options>: Send packets with specified ip options--ttl <val>: Set IP time-to-live field--spoof-mac <mac address/prefix/vendor name>: Spoof your MAC address--badsum: Send packets with a bogus TCP/UDP/SCTP checksum
OUTPUT:-oN/-oX/-oS/-oG <file>: Output scan in normal, XML, s|<rIpt kIddi3,and Grepable format, respectively, to the given filename.-oA <basename>: Output in the three major formats at once-v: Increase verbosity level (use -vv or more for greater effect)-d: Increase debugging level (use -dd or more for greater effect)--reason: Display the reason a port is in a particular state--open: Only show open (or possibly open) ports--packet-trace: Show all packets sent and received--iflist: Print host interfaces and routes (for debugging)--append-output: Append to rather than clobber specified output files--resume <filename>: Resume an aborted scan--stylesheet <path/URL>: XSL stylesheet to transform XML output to HTML--webxml: Reference stylesheet from Nmap.Org for more portable XML--no-stylesheet: Prevent associating of XSL stylesheet w/XML output
MISC:-6: Enable IPv6 scanning-A: Enable OS detection, version detection, script scanning, and traceroute--datadir <dirname>: Specify custom Nmap data file location--send-eth/--send-ip: Send using raw ethernet frames or IP packets--privileged: Assume that the user is fully privileged--unprivileged: Assume the user lacks raw socket privileges-V: Print version number-h: Print this help summary page.
EXAMPLES:nmap -v -A scanme.nmap.orgnmap -v -sn 192.168.0.0/16 10.0.0.0/8nmap -v -iR 10000 -Pn -p 80
SEE THE MAN PAGE (https://nmap.org/book/man.html) FOR MORE OPTIONS AND EXAMPLES
lxk@lxk:~$
AI 總結(jié)一下就是
根據(jù)
nmap
的幫助文檔,以下是各類可選參數(shù)的詳細(xì)分析,按功能類別劃分:1. 目標(biāo)指定(Target Specification)
iL <inputfilename>
: 從一個(gè)主機(jī)或網(wǎng)絡(luò)列表中輸入目標(biāo)。iR <num hosts>
: 隨機(jī)選擇目標(biāo)進(jìn)行掃描。-exclude <host1[,host2],...]
: 排除指定的主機(jī)或網(wǎng)絡(luò)。-excludefile <exclude_file>
: 從文件中排除目標(biāo)列表。2. 主機(jī)發(fā)現(xiàn)(Host Discovery)
sL
: 列出掃描目標(biāo),不進(jìn)行實(shí)際掃描。sn
: 僅進(jìn)行主機(jī)存活性檢測(禁用端口掃描)。Pn
: 將所有主機(jī)視為在線,跳過主機(jī)發(fā)現(xiàn)。PS/PA/PU/PY[portlist]
: 使用 TCP SYN/ACK、UDP 或 SCTP 協(xié)議進(jìn)行主機(jī)發(fā)現(xiàn)。PE/PP/PM
: 使用 ICMP 回顯請(qǐng)求、時(shí)間戳請(qǐng)求或子網(wǎng)掩碼請(qǐng)求進(jìn)行主機(jī)發(fā)現(xiàn)。PO[protocol list]
: 發(fā)送指定協(xié)議的 IP 協(xié)議探測包。n/-R
: 不進(jìn)行 DNS 解析(n
)或始終解析(R
)。-dns-servers <serv1[,serv2],...]
: 指定自定義 DNS 服務(wù)器。-system-dns
: 使用操作系統(tǒng)的 DNS 解析器。-traceroute
: 跟蹤到每個(gè)主機(jī)的跳躍路徑。3. 掃描技術(shù)(Scan Techniques)
sS
: TCP SYN 掃描(默認(rèn)掃描方式)。sT
: TCP 連接掃描。sA
: TCP ACK 掃描。sW
: TCP 窗口掃描。sM
: TCP Maimon 掃描。sU
: UDP 掃描。sN/sF/sX
: TCP Null 掃描、FIN 掃描和 Xmas 掃描。-scanflags <flags>
: 定制 TCP 掃描標(biāo)志。sI <zombie host[:probeport]>
: 使用閑置主機(jī)進(jìn)行掃描(Idle 掃描)。sY/sZ
: SCTP INIT/COOKIE-ECHO 掃描。sO
: IP 協(xié)議掃描。b <FTP relay host>
: FTP 跳躍掃描。4. 端口指定與掃描順序(Port Specification and Scan Order)
p <port ranges>
: 僅掃描指定的端口(可指定范圍)。-exclude-ports <port ranges>
: 排除指定的端口。F
: 快速模式,掃描較少的端口。r
: 順序掃描端口,避免隨機(jī)化。-top-ports <number>
: 掃描最常見的前<number>
個(gè)端口。-port-ratio <ratio>
: 掃描比給定比率更常見的端口。5. 服務(wù)/版本檢測(Service/Version Detection)
sV
: 探測開放端口以確定服務(wù)和版本信息。-version-intensity <level>
: 設(shè)置版本探測強(qiáng)度,從 0(輕量)到 9(全面嘗試所有探測)。-version-light
: 限制為最可能的探測(強(qiáng)度為 2)。-version-all
: 嘗試所有版本探測(強(qiáng)度為 9)。-version-trace
: 顯示詳細(xì)的版本掃描活動(dòng)(用于調(diào)試)。6. 腳本掃描(Script Scan)
sC
: 等同于-script=default
,使用默認(rèn)腳本進(jìn)行掃描。-script=<Lua scripts>
: 執(zhí)行指定的 Lua 腳本(可指定腳本文件或類別)。-script-args=<n1=v1,[n2=v2,...]>
: 向腳本傳遞參數(shù)。-script-args-file=filename
: 從文件提供腳本參數(shù)。-script-trace
: 顯示所有發(fā)送和接收的數(shù)據(jù)。-script-updatedb
: 更新腳本數(shù)據(jù)庫。-script-help=<Lua scripts>
: 顯示指定腳本的幫助信息。7. 操作系統(tǒng)檢測(OS Detection)
O
: 啟用操作系統(tǒng)檢測。-osscan-limit
: 限制操作系統(tǒng)檢測僅限于可能的目標(biāo)。-osscan-guess
: 更積極地猜測操作系統(tǒng)。8. 定時(shí)與性能(Timing and Performance)
T<0-5>
: 設(shè)置掃描的時(shí)間模板,越高越快。-min-hostgroup/max-hostgroup <size>
: 設(shè)置并行掃描主機(jī)的大小。-min-parallelism/max-parallelism <numprobes>
: 設(shè)置探測并行化程度。-min-rtt-timeout/max-rtt-timeout/initial-rtt-timeout <time>
: 設(shè)置探測的往返時(shí)間。-max-retries <tries>
: 限制端口掃描重試次數(shù)。-host-timeout <time>
: 設(shè)置掃描目標(biāo)的超時(shí)時(shí)間。-scan-delay/--max-scan-delay <time>
: 設(shè)置掃描探測之間的延遲。-min-rate <number>
: 設(shè)置每秒發(fā)送最少的包數(shù)。-max-rate <number>
: 設(shè)置每秒發(fā)送最多的包數(shù)。9. 防火墻/IDS 規(guī)避與欺騙(Firewall/IDS Evasion and Spoofing)
f
/-mtu <val>
: 將包進(jìn)行分片。D <decoy1,decoy2[,ME],...>
: 使用偽裝主機(jī)進(jìn)行掃描。S <IP_Address>
: 欺騙源地址。e <iface>
: 使用指定的網(wǎng)絡(luò)接口。g/--source-port <portnum>
: 使用指定的源端口。-proxies <url1,[url2],...>
: 通過 HTTP/SOCKS4 代理轉(zhuǎn)發(fā)連接。-data <hex string>
: 在發(fā)送的包中附加自定義十六進(jìn)制負(fù)載。-data-string <string>
: 在發(fā)送的包中附加自定義 ASCII 字符串。-data-length <num>
: 在發(fā)送的包中附加隨機(jī)數(shù)據(jù)。-ip-options <options>
: 發(fā)送帶有指定 IP 選項(xiàng)的包。-ttl <val>
: 設(shè)置 IP 的生存時(shí)間。-spoof-mac <mac address/prefix/vendor name>
: 欺騙 MAC 地址。-badsum
: 發(fā)送帶有無效 TCP/UDP/SCTP 校驗(yàn)和的包。10. 輸出(Output)
oN/-oX/-oS/-oG <file>
: 將掃描結(jié)果輸出為正常、XML、腳本、可搜索格式。oA <basename>
: 同時(shí)輸出為三種主要格式。v
: 增加輸出詳細(xì)程度(可通過vv
或更多級(jí)別進(jìn)一步增強(qiáng))。d
: 增加調(diào)試級(jí)別(使用dd
或更多級(jí)別進(jìn)一步增強(qiáng))。-reason
: 顯示端口處于某一狀態(tài)的原因。-open
: 僅顯示開放(或可能開放)端口。-packet-trace
: 顯示所有發(fā)送和接收的包。-iflist
: 打印主機(jī)的接口和路由信息(用于調(diào)試)。-append-output
: 追加輸出到指定的文件。-resume <filename>
: 恢復(fù)中斷的掃描。-stylesheet <path/URL>
: 使用指定的 XSL 樣式表將 XML 輸出轉(zhuǎn)換為 HTML。-webxml
: 使用 Nmap.Org 提供的樣式表,以確保 XML 輸出在不同環(huán)境下都能轉(zhuǎn)換為 HTML。-no-stylesheet
: 防止 XML 輸出與 XSL 樣式表關(guān)聯(lián)。11. Miscellaneous(雜項(xiàng))
6
: 啟用 IPv6 掃描。A
: 啟用操作系統(tǒng)檢測、版本檢測、腳本掃描和 traceroute。-datadir <dirname>
: 指定自定義的 Nmap 數(shù)據(jù)文件位置。-send-eth/--send-ip
: 使用原始以太網(wǎng)
結(jié)合這些選項(xiàng),如果想要掃描指定子網(wǎng)與網(wǎng)段下當(dāng)前連接的所有設(shè)備的IP與通信時(shí)延,例如掃描 51 網(wǎng)段,子網(wǎng)掩碼設(shè)置為 255.255.255.0(高24位都是1,所以是 192.168.51.0/24
),可以執(zhí)行。
nmap -sn -T5 -n --min-parallelism 50 --max-parallelism 100 192.168.51.0/24
sn
:Ping 掃描,跳過端口掃描,僅識(shí)別在線主機(jī)。T5
:設(shè)置掃描速度為較高級(jí)別(5 是最快的,但 T4 適合大多數(shù)情況)。n
:禁用 DNS 解析,避免查詢域名。-min-parallelism 10
:設(shè)置最小并行掃描數(shù)為 50。-max-parallelism 100
:設(shè)置最大并行掃描數(shù)為 100(根據(jù)系統(tǒng)性能可以調(diào)整)。192.168.51.0/24
:指定掃描的 IP 子網(wǎng)和網(wǎng)段。
這個(gè)命令會(huì)在子網(wǎng) 192.168.51.0/24
中盡可能快地掃描設(shè)備并識(shí)別哪些主機(jī)在線(192.168.51.1-192.168.51.255),而不進(jìn)行端口掃描。通過高并行度和快速模式,能夠加速掃描過程,掃描結(jié)果具有如下形式
Starting Nmap 7.80 ( https://nmap.org ) at 2024-xx-xx 15:39 CST
Nmap scan report for 192.168.51.1
Host is up (0.00090s latency).
Nmap scan report for 192.168.51.9
Host is up (0.00062s latency).
Nmap done: 256 IP addresses (2 hosts up) scanned in 1.61 seconds
如果還想要掃描在線設(shè)備的 MAC 地址,可以加 sudo 權(quán)限
sudo nmap -sn -T5 -n --min-parallelism 50 --max-parallelism 100 192.168.51.0/24
結(jié)果如下,多了 MAC 信息
Starting Nmap 7.80 ( https://nmap.org ) at 2024-xx-xx 15:46 CST
Nmap scan report for 192.168.51.1
Host is up (0.00041s latency).
MAC Address: 68:XX:XX:XX:XX:XX (Unknown)
Nmap scan report for 192.168.51.9
Host is up.
Nmap done: 256 IP addresses (2 hosts up) scanned in 0.63 seconds