包包網站建設策劃書seo搜索優(yōu)化專員招聘
【Linux】獲得同一子網下當前在線設備IP/Latency/MAC 通過nmap指定CIDR掃描當前在線設備
通過路由器的后臺,查看當前在線設備,受到網卡版本的影響,有時會有部分設備看不見MAC和分配的IP。此時,可以借助命令行工具掃描子網下所有連接的設備信息與通信狀態(tài)。
Nmap 是一個強大的網絡掃描工具,提供了豐富的功能,用于發(fā)現網絡中的主機、服務、操作系統、版本、漏洞等信息。
安裝方法
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 總結一下就是
根據
nmap
的幫助文檔,以下是各類可選參數的詳細分析,按功能類別劃分:1. 目標指定(Target Specification)
iL <inputfilename>
: 從一個主機或網絡列表中輸入目標。iR <num hosts>
: 隨機選擇目標進行掃描。-exclude <host1[,host2],...]
: 排除指定的主機或網絡。-excludefile <exclude_file>
: 從文件中排除目標列表。2. 主機發(fā)現(Host Discovery)
sL
: 列出掃描目標,不進行實際掃描。sn
: 僅進行主機存活性檢測(禁用端口掃描)。Pn
: 將所有主機視為在線,跳過主機發(fā)現。PS/PA/PU/PY[portlist]
: 使用 TCP SYN/ACK、UDP 或 SCTP 協議進行主機發(fā)現。PE/PP/PM
: 使用 ICMP 回顯請求、時間戳請求或子網掩碼請求進行主機發(fā)現。PO[protocol list]
: 發(fā)送指定協議的 IP 協議探測包。n/-R
: 不進行 DNS 解析(n
)或始終解析(R
)。-dns-servers <serv1[,serv2],...]
: 指定自定義 DNS 服務器。-system-dns
: 使用操作系統的 DNS 解析器。-traceroute
: 跟蹤到每個主機的跳躍路徑。3. 掃描技術(Scan Techniques)
sS
: TCP SYN 掃描(默認掃描方式)。sT
: TCP 連接掃描。sA
: TCP ACK 掃描。sW
: TCP 窗口掃描。sM
: TCP Maimon 掃描。sU
: UDP 掃描。sN/sF/sX
: TCP Null 掃描、FIN 掃描和 Xmas 掃描。-scanflags <flags>
: 定制 TCP 掃描標志。sI <zombie host[:probeport]>
: 使用閑置主機進行掃描(Idle 掃描)。sY/sZ
: SCTP INIT/COOKIE-ECHO 掃描。sO
: IP 協議掃描。b <FTP relay host>
: FTP 跳躍掃描。4. 端口指定與掃描順序(Port Specification and Scan Order)
p <port ranges>
: 僅掃描指定的端口(可指定范圍)。-exclude-ports <port ranges>
: 排除指定的端口。F
: 快速模式,掃描較少的端口。r
: 順序掃描端口,避免隨機化。-top-ports <number>
: 掃描最常見的前<number>
個端口。-port-ratio <ratio>
: 掃描比給定比率更常見的端口。5. 服務/版本檢測(Service/Version Detection)
sV
: 探測開放端口以確定服務和版本信息。-version-intensity <level>
: 設置版本探測強度,從 0(輕量)到 9(全面嘗試所有探測)。-version-light
: 限制為最可能的探測(強度為 2)。-version-all
: 嘗試所有版本探測(強度為 9)。-version-trace
: 顯示詳細的版本掃描活動(用于調試)。6. 腳本掃描(Script Scan)
sC
: 等同于-script=default
,使用默認腳本進行掃描。-script=<Lua scripts>
: 執(zhí)行指定的 Lua 腳本(可指定腳本文件或類別)。-script-args=<n1=v1,[n2=v2,...]>
: 向腳本傳遞參數。-script-args-file=filename
: 從文件提供腳本參數。-script-trace
: 顯示所有發(fā)送和接收的數據。-script-updatedb
: 更新腳本數據庫。-script-help=<Lua scripts>
: 顯示指定腳本的幫助信息。7. 操作系統檢測(OS Detection)
O
: 啟用操作系統檢測。-osscan-limit
: 限制操作系統檢測僅限于可能的目標。-osscan-guess
: 更積極地猜測操作系統。8. 定時與性能(Timing and Performance)
T<0-5>
: 設置掃描的時間模板,越高越快。-min-hostgroup/max-hostgroup <size>
: 設置并行掃描主機的大小。-min-parallelism/max-parallelism <numprobes>
: 設置探測并行化程度。-min-rtt-timeout/max-rtt-timeout/initial-rtt-timeout <time>
: 設置探測的往返時間。-max-retries <tries>
: 限制端口掃描重試次數。-host-timeout <time>
: 設置掃描目標的超時時間。-scan-delay/--max-scan-delay <time>
: 設置掃描探測之間的延遲。-min-rate <number>
: 設置每秒發(fā)送最少的包數。-max-rate <number>
: 設置每秒發(fā)送最多的包數。9. 防火墻/IDS 規(guī)避與欺騙(Firewall/IDS Evasion and Spoofing)
f
/-mtu <val>
: 將包進行分片。D <decoy1,decoy2[,ME],...>
: 使用偽裝主機進行掃描。S <IP_Address>
: 欺騙源地址。e <iface>
: 使用指定的網絡接口。g/--source-port <portnum>
: 使用指定的源端口。-proxies <url1,[url2],...>
: 通過 HTTP/SOCKS4 代理轉發(fā)連接。-data <hex string>
: 在發(fā)送的包中附加自定義十六進制負載。-data-string <string>
: 在發(fā)送的包中附加自定義 ASCII 字符串。-data-length <num>
: 在發(fā)送的包中附加隨機數據。-ip-options <options>
: 發(fā)送帶有指定 IP 選項的包。-ttl <val>
: 設置 IP 的生存時間。-spoof-mac <mac address/prefix/vendor name>
: 欺騙 MAC 地址。-badsum
: 發(fā)送帶有無效 TCP/UDP/SCTP 校驗和的包。10. 輸出(Output)
oN/-oX/-oS/-oG <file>
: 將掃描結果輸出為正常、XML、腳本、可搜索格式。oA <basename>
: 同時輸出為三種主要格式。v
: 增加輸出詳細程度(可通過vv
或更多級別進一步增強)。d
: 增加調試級別(使用dd
或更多級別進一步增強)。-reason
: 顯示端口處于某一狀態(tài)的原因。-open
: 僅顯示開放(或可能開放)端口。-packet-trace
: 顯示所有發(fā)送和接收的包。-iflist
: 打印主機的接口和路由信息(用于調試)。-append-output
: 追加輸出到指定的文件。-resume <filename>
: 恢復中斷的掃描。-stylesheet <path/URL>
: 使用指定的 XSL 樣式表將 XML 輸出轉換為 HTML。-webxml
: 使用 Nmap.Org 提供的樣式表,以確保 XML 輸出在不同環(huán)境下都能轉換為 HTML。-no-stylesheet
: 防止 XML 輸出與 XSL 樣式表關聯。11. Miscellaneous(雜項)
6
: 啟用 IPv6 掃描。A
: 啟用操作系統檢測、版本檢測、腳本掃描和 traceroute。-datadir <dirname>
: 指定自定義的 Nmap 數據文件位置。-send-eth/--send-ip
: 使用原始以太網
結合這些選項,如果想要掃描指定子網與網段下當前連接的所有設備的IP與通信時延,例如掃描 51 網段,子網掩碼設置為 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 掃描,跳過端口掃描,僅識別在線主機。T5
:設置掃描速度為較高級別(5 是最快的,但 T4 適合大多數情況)。n
:禁用 DNS 解析,避免查詢域名。-min-parallelism 10
:設置最小并行掃描數為 50。-max-parallelism 100
:設置最大并行掃描數為 100(根據系統性能可以調整)。192.168.51.0/24
:指定掃描的 IP 子網和網段。
這個命令會在子網 192.168.51.0/24
中盡可能快地掃描設備并識別哪些主機在線(192.168.51.1-192.168.51.255),而不進行端口掃描。通過高并行度和快速模式,能夠加速掃描過程,掃描結果具有如下形式
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
如果還想要掃描在線設備的 MAC 地址,可以加 sudo 權限
sudo nmap -sn -T5 -n --min-parallelism 50 --max-parallelism 100 192.168.51.0/24
結果如下,多了 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