首页
学习
活动
专区
圈层
工具
发布
社区首页 >专栏 >LINUX常用100条命令总结【二】

LINUX常用100条命令总结【二】

原创
作者头像
好派笔记
修改2021-09-13 14:36:10
修改2021-09-13 14:36:10
8770
举报
文章被收录于专栏:好派笔记好派笔记
8.2 wget

功能: 非交互式的网络文件下载工具。

语法:

代码语言:javascript
复制
 wget [选项]... [URL]...

参数:

代码语言:javascript
复制
启动:
  -V,  --version           显示 Wget 的版本信息并退出。
  -h,  --help              打印此帮助。
  -b,  --background        启动后转入后台。
  -e,  --execute=COMMAND   运行一个“.wgetrc”风格的命令。

日志和输入文件:
  -o,  --output-file=FILE    将日志信息写入 FILE。
  -a,  --append-output=FILE  将信息添加至 FILE。
  -d,  --debug               打印大量调试信息。
  -q,  --quiet               安静模式 (无信息输出)。
  -v,  --verbose             详尽的输出 (此为默认值)。
  -nv, --no-verbose          关闭详尽输出,但不进入安静模式。
       --report-speed=TYPE   Output bandwidth as TYPE.  TYPE can be bits.
  -i,  --input-file=FILE     下载本地或外部 FILE 中的 URLs。
  -F,  --force-html          把输入文件当成 HTML 文件。
  -B,  --base=URL            解析与 URL 相关的
                             HTML 输入文件 (由 -i -F 选项指定)。
       --config=FILE         Specify config file to use.

下载:
  -t,  --tries=NUMBER            设置重试次数为 NUMBER (0 代表无限制)。
       --retry-connrefused       即使拒绝连接也是重试。
  -O,  --output-document=FILE    将文档写入 FILE。
  -nc, --no-clobber              skip downloads that would download to
                                 existing files (overwriting them).
  -c,  --continue                断点续传下载文件。
       --progress=TYPE           选择进度条类型。
  -N,  --timestamping            只获取比本地文件新的文件。
  --no-use-server-timestamps     不用服务器上的时间戳来设置本地文件。
  -S,  --server-response         打印服务器响应。
       --spider                  不下载任何文件。
  -T,  --timeout=SECONDS         将所有超时设为 SECONDS 秒。
       --dns-timeout=SECS        设置 DNS 查寻超时为 SECS 秒。
       --connect-timeout=SECS    设置连接超时为 SECS 秒。
       --read-timeout=SECS       设置读取超时为 SECS 秒。
  -w,  --wait=SECONDS            等待间隔为 SECONDS 秒。
       --waitretry=SECONDS       在获取文件的重试期间等待 1..SECONDS 秒。
       --random-wait             获取多个文件时,每次随机等待间隔
                                 0.5*WAIT...1.5*WAIT 秒。
       --no-proxy                禁止使用代理。
  -Q,  --quota=NUMBER            设置获取配额为 NUMBER 字节。
       --bind-address=ADDRESS    绑定至本地主机上的 ADDRESS (主机名或是 IP)。
       --limit-rate=RATE         限制下载速率为 RATE。
       --no-dns-cache            关闭 DNS 查寻缓存。
       --restrict-file-names=OS  限定文件名中的字符为 OS 允许的字符。
       --ignore-case             匹配文件/目录时忽略大小写。
  -4,  --inet4-only              仅连接至 IPv4 地址。
  -6,  --inet6-only              仅连接至 IPv6 地址。
       --prefer-family=FAMILY    首先连接至指定协议的地址
                                 FAMILY 为 IPv6,IPv4 或是 none。
       --user=USER               将 ftp 和 http 的用户名均设置为 USER。
       --password=PASS           将 ftp 和 http 的密码均设置为 PASS。
       --ask-password            提示输入密码。
       --no-iri                  关闭 IRI 支持。
       --local-encoding=ENC      IRI (国际化资源标识符) 使用 ENC 作为本地编码。
       --remote-encoding=ENC     使用 ENC 作为默认远程编码。
       --unlink                  remove file before clobber.

目录:
  -nd, --no-directories           不创建目录。
  -x,  --force-directories        强制创建目录。
  -nH, --no-host-directories      不要创建主目录。
       --protocol-directories     在目录中使用协议名称。
  -P,  --directory-prefix=PREFIX  以 PREFIX/... 保存文件
       --cut-dirs=NUMBER          忽略远程目录中 NUMBER 个目录层。

HTTP 选项:
       --http-user=USER        设置 http 用户名为 USER。
       --http-password=PASS    设置 http 密码为 PASS。
       --no-cache              不在服务器上缓存数据。
       --default-page=NAME     改变默认页
                               (默认页通常是“index.html”)。
  -E,  --adjust-extension      以合适的扩展名保存 HTML/CSS 文档。
       --ignore-length         忽略头部的‘Content-Length’区域。
       --header=STRING         在头部插入 STRING。
       --max-redirect          每页所允许的最大重定向。
       --proxy-user=USER       使用 USER 作为代理用户名。
       --proxy-password=PASS   使用 PASS 作为代理密码。
       --referer=URL           在 HTTP 请求头包含‘Referer: URL’。
       --save-headers          将 HTTP 头保存至文件。
  -U,  --user-agent=AGENT      标识为 AGENT 而不是 Wget/VERSION。
       --no-http-keep-alive    禁用 HTTP keep-alive (永久连接)。
       --no-cookies            不使用 cookies。
       --load-cookies=FILE     会话开始前从 FILE 中载入 cookies。
       --save-cookies=FILE     会话结束后保存 cookies 至 FILE。
       --keep-session-cookies  载入并保存会话 (非永久) cookies。
       --post-data=STRING      使用 POST 方式;把 STRING 作为数据发送。
       --post-file=FILE        使用 POST 方式;发送 FILE 内容。
       --content-disposition   当选中本地文件名时
                               允许 Content-Disposition 头部 (尚在实验)。
       --content-on-error      output the received content on server errors.
       --auth-no-challenge     发送不含服务器询问的首次等待
                               的基本 HTTP 验证信息。

HTTPS (SSL/TLS) 选项:
       --secure-protocol=PR     选择安全协议,可以是 auto、SSLv2、
                                SSLv3 或是 TLSv1 中的一个。
       --no-check-certificate   不要验证服务器的证书。
       --certificate=FILE       客户端证书文件。
       --certificate-type=TYPE  客户端证书类型,PEM 或 DER。
       --private-key=FILE       私钥文件。
       --private-key-type=TYPE  私钥文件类型,PEM 或 DER。
       --ca-certificate=FILE    带有一组 CA 认证的文件。
       --ca-directory=DIR       保存 CA 认证的哈希列表的目录。
       --random-file=FILE       带有生成 SSL PRNG 的随机数据的文件。
       --egd-file=FILE          用于命名带有随机数据的 EGD 套接字的文件。

FTP 选项:
       --ftp-user=USER         设置 ftp 用户名为 USER。
       --ftp-password=PASS     设置 ftp 密码为 PASS。
       --no-remove-listing     不要删除‘.listing’文件。
       --no-glob               不在 FTP 文件名中使用通配符展开。
       --no-passive-ftp        禁用“passive”传输模式。
       --preserve-permissions  保留远程文件的权限。
       --retr-symlinks         递归目录时,获取链接的文件 (而非目录)。

WARC options:
       --warc-file=FILENAME      save request/response data to a .warc.gz file.
       --warc-header=STRING      insert STRING into the warcinfo record.
       --warc-max-size=NUMBER    set maximum size of WARC files to NUMBER.
       --warc-cdx                write CDX index files.
       --warc-dedup=FILENAME     do not store records listed in this CDX file.
       --no-warc-compression     do not compress WARC files with GZIP.
       --no-warc-digests         do not calculate SHA1 digests.
       --no-warc-keep-log        do not store the log file in a WARC record.
       --warc-tempdir=DIRECTORY  location for temporary files created by the
                                 WARC writer.

递归下载:
  -r,  --recursive          指定递归下载。
  -l,  --level=NUMBER       最大递归深度 (inf 或 0 代表无限制,即全部下载)。
       --delete-after       下载完成后删除本地文件。
  -k,  --convert-links      让下载得到的 HTML 或 CSS 中的链接指向本地文件。
  --backups=N   before writing file X, rotate up to N backup files.
  -K,  --backup-converted   在转换文件 X 前先将它备份为 X.orig。
  -m,  --mirror             -N -r -l inf --no-remove-listing 的缩写形式。
  -p,  --page-requisites    下载所有用于显示 HTML 页面的图片之类的元素。
       --strict-comments    用严格方式 (SGML) 处理 HTML 注释。

递归接受/拒绝:
  -A,  --accept=LIST               逗号分隔的可接受的扩展名列表。
  -R,  --reject=LIST               逗号分隔的要拒绝的扩展名列表。
       --accept-regex=REGEX        regex matching accepted URLs.
       --reject-regex=REGEX        regex matching rejected URLs.
       --regex-type=TYPE           regex type (posix|pcre).
  -D,  --domains=LIST              逗号分隔的可接受的域列表。
       --exclude-domains=LIST      逗号分隔的要拒绝的域列表。
       --follow-ftp                跟踪 HTML 文档中的 FTP 链接。
       --follow-tags=LIST          逗号分隔的跟踪的 HTML 标识列表。
       --ignore-tags=LIST          逗号分隔的忽略的 HTML 标识列表。
  -H,  --span-hosts                递归时转向外部主机。
  -L,  --relative                  只跟踪有关系的链接。
  -I,  --include-directories=LIST  允许目录的列表。
  --trust-server-names             use the name specified by the redirection
                                   url last component.
  -X,  --exclude-directories=LIST  排除目录的列表。
  -np, --no-parent                 不追溯至父目录。

实例:

  • 使用wget -O下载并以不同的文件名保存(-O:下载文件到对应目录,并且修改文件名称)
代码语言:javascript
复制
[root@LVS ~]# wget -O index.zip http://www.haopython.com
--2020-04-15 14:41:24--  http://www.haopython.com/
正在解析主机 www.haopython.com (www.haopython.com)... 212.64.86.215
正在连接 www.haopython.com (www.haopython.com)|212.64.86.215|:80... 已连接。
已发出 HTTP 请求,正在等待回应... 200 OK
长度:未指定 [text/html]
正在保存至: “index.zip”

    [  <=>                                                                                                         ] 90,566       221KB/s 用时 0.4s   

2020-04-15 14:41:25 (221 KB/s) - “index.zip” 已保存 [90566]
  • 使用wget -b后台下载,可以使用tail -f wget-log查看进度
代码语言:javascript
复制
[root@LVS ~]# wget -b  http://www.haopython.com
继续在后台运行,pid 为 17404。
将把输出写入至 “wget-log”。

[root@LVS ~]

# tail -f wget-log 正在连接 www.haopython.com (www.haopython.com)|212.64.86.215|:80... 已连接。 已发出 HTTP 请求,正在等待回应... 200 OK 长度:未指定 [text/html] 正在保存至: “index.html.1” 0K .......... .......... .......... .......... .......... 174K 50K .......... .......... .......... ........ 321K=0.4s 2020-04-15 14:45:52 (217 KB/s) - “index.html.1” 已保存 [90566]

  • 利用-spider: 模拟下载 ,不会下载,只是会检查是否网站是否好着
代码语言:javascript
复制
[root@LVS ~]# wget --spider http://www.haopython.com
开启 Spider 模式。检查是否存在远程文件。
--2020-04-15 14:48:46--  http://www.haopython.com/
正在解析主机 www.haopython.com (www.haopython.com)... 212.64.86.215
正在连接 www.haopython.com (www.haopython.com)|212.64.86.215|:80... 已连接。
已发出 HTTP 请求,正在等待回应... 200 OK
长度:未指定 [text/html]
存在远程文件且该文件可能含有更深层的链接,
但不能进行递归操作 -- 无法获取。
  • 模拟下载打印服务器响应
代码语言:javascript
复制
[root@LVS ~]# wget -S http://www.haopython.com
--2020-04-15 14:50:48--  http://www.haopython.com/
正在解析主机 www.haopython.com (www.haopython.com)... 212.64.86.215
正在连接 www.haopython.com (www.haopython.com)|212.64.86.215|:80... 已连接。
已发出 HTTP 请求,正在等待回应... 
  HTTP/1.1 200 OK
  Server: nginx
  Date: Wed, 15 Apr 2020 06:50:49 GMT
  Content-Type: text/html; charset=UTF-8
  Transfer-Encoding: chunked
  Connection: keep-alive
  Keep-Alive: timeout=60
  Link: <http://www.haopython.com/wp-json/>; rel="https://api.w.org/"
长度:未指定 [text/html]
正在保存至: “index.html.2”

    [  <=>                                                                                                         ] 90,566       217KB/s 用时 0.4s   

2020-04-15 14:50:49 (217 KB/s) - “index.html.2” 已保存 [90566]
  • 设定指定次数
代码语言:javascript
复制
[root@LVS ~]# wget -r --tries=2  www.haopython.com
--2020-04-15 14:53:45--  http://www.haopython.com/
正在解析主机 www.haopython.com (www.haopython.com)... 212.64.86.215
正在连接 www.haopython.com (www.haopython.com)|212.64.86.215|:80... 已连接。
已发出 HTTP 请求,正在等待回应... 200 OK
长度:未指定 [text/html]
正在保存至: “www.haopython.com/index.html”

    [  <=>                                                                                                         ] 90,566       231KB/s 用时 0.4s   

2020-04-15 14:53:45 (231 KB/s) - “www.haopython.com/index.html” 已保存 [90566]

正在载入 robots.txt;请忽略错误消息。
--2020-04-15 14:53:45--  http://www.haopython.com/robots.txt
再次使用存在的到 www.haopython.com:80 的连接。
已发出 HTTP 请求,正在等待回应... 200 OK
长度:未指定 [text/plain]
正在保存至: “www.haopython.com/robots.txt”

    [ <=>                                                                                                          ] 67          --.-K/s 用时 0s      

2020-04-15 14:53:46 (664 KB/s) - “www.haopython.com/robots.txt” 已保存 [67]
8.3 ping

功能: 测试主机之间网络的连通性。

语法:

代码语言:javascript
复制
ping [-dfnqrRv][-c<完成次数>][-i<间隔秒数>][-I<网络界面>][-l<前置载入>][-p<范本样式>][-s<数据包大小>][-t<存活数值>][主机名称或IP地址]

参数:

代码语言:javascript
复制
-d 使用Socket的SO_DEBUG功能。
-c<完成次数> 设置完成要求回应的次数。
-f 极限检测。
-i<间隔秒数> 指定收发信息的间隔时间。
-I<网络界面> 使用指定的网络接口送出数据包。
-l<前置载入> 设置在送出要求信息之前,先行发出的数据包。
-n 只输出数值。
-p<范本样式> 设置填满数据包的范本样式。
-q 不显示指令执行过程,开头和结尾的相关信息除外。
-r 忽略普通的Routing Table,直接将数据包送到远端主机上。
-R 记录路由过程。
-s<数据包大小> 设置数据包的大小。
-t<存活数值> 设置存活数值TTL的大小。
-v 详细显示指令的执行过程。

实例:

  • 检测是否与主机连通
代码语言:javascript
复制
[root@LVS ~]# ping www.haopython.com
PING www.haopython.com (212.64.86.215) 56(84) bytes of data.
^C
--- www.haopython.com ping statistics ---
17 packets transmitted, 0 received, 100% packet loss, time 16013ms

[root@LVS ~]

# ping www.baidu.com PING www.a.shifen.com (220.181.38.150) 56(84) bytes of data. 64 bytes from 220.181.38.150 (220.181.38.150): icmp_seq=1 ttl=53 time=22.3 ms 64 bytes from 220.181.38.150 (220.181.38.150): icmp_seq=2 ttl=53 time=22.2 ms ^C --- www.a.shifen.com ping statistics --- 2 packets transmitted, 2 received, 0% packet loss, time 1001ms rtt min/avg/max/mdev = 22.249/22.295/22.342/0.156 ms

[root@LVS ~]

#

  • 指定接收包的次数
代码语言:javascript
复制
[root@LVS ~]# ping -c 6 www.baidu.com
PING www.baidu.com (220.181.38.150) 56(84) bytes of data.
64 bytes from 220.181.38.150 (220.181.38.150): icmp_seq=1 ttl=53 time=21.8 ms
64 bytes from 220.181.38.150 (220.181.38.150): icmp_seq=2 ttl=53 time=25.0 ms
64 bytes from 220.181.38.150 (220.181.38.150): icmp_seq=3 ttl=53 time=21.6 ms
64 bytes from 220.181.38.150 (220.181.38.150): icmp_seq=4 ttl=53 time=21.5 ms
64 bytes from 220.181.38.150 (220.181.38.150): icmp_seq=5 ttl=53 time=27.3 ms
64 bytes from 220.181.38.150 (220.181.38.150): icmp_seq=6 ttl=53 time=22.2 ms

--- www.baidu.com ping statistics ---
6 packets transmitted, 6 received, 0% packet loss, time 5011ms
rtt min/avg/max/mdev = 21.526/23.265/27.315/2.171 ms

[root@LVS ~]

#

  • 指定发送周期为3秒包大小1000Byte和TTL时间linux下ping包的默认大小为64Byte,次数不限。但有时我们需要尝试ping大数据包,来测试网络的状况,这时,就要指定ping包的大小了。
代码语言:javascript
复制
[root@LVS ~]# ping -i 3 -s 1000 -t 255 -c 2 www.baidu.com
PING www.baidu.com (220.181.38.150) 1000(1028) bytes of data.
1008 bytes from 220.181.38.150 (220.181.38.150): icmp_seq=1 ttl=53 time=24.2 ms
1008 bytes from 220.181.38.150 (220.181.38.150): icmp_seq=2 ttl=53 time=27.0 ms

--- www.baidu.com ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 3004ms
rtt min/avg/max/mdev = 24.267/25.676/27.085/1.409 ms
8.4 route

功能:显示和设置 linux 系统的路由表。

实例:

  • 查看本机路由表
代码语言:javascript
复制
[root@LVS ~]# route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         192.168.100.1   0.0.0.0         UG    100    0        0 ens33
192.168.100.0   0.0.0.0         255.255.255.0   U     100    0        0 ens33
192.168.122.0   0.0.0.0         255.255.255.0   U     0      0        0 virbr0

[root@LVS ~]

#

8.5 ifconfig

功能: 命令用于显示或设置网络设备。

语法:

代码语言:javascript
复制
ifconfig [网络设备][down up -allmulti -arp -promisc][add<地址>][del<地址>][<hw<网络设备类型><硬件地址>][io_addr<I/O地址>][irq<IRQ地址>][media<网络媒介类型>][mem_start<内存地址>][metric<数目>][mtu<字节>][netmask<子网掩码>][tunnel<地址>][-broadcast<地址>][-pointopoint<地址>][IP地址]

参数:

代码语言:javascript
复制
add<地址> 设置网络设备IPv6的IP地址。
del<地址> 删除网络设备IPv6的IP地址。
down 关闭指定的网络设备。
<hw<网络设备类型><硬件地址> 设置网络设备的类型与硬件地址。
io_addr<I/O地址> 设置网络设备的I/O地址。
irq<IRQ地址> 设置网络设备的IRQ。
media<网络媒介类型> 设置网络设备的媒介类型。
mem_start<内存地址> 设置网络设备在主内存所占用的起始地址。
metric<数目> 指定在计算数据包的转送次数时,所要加上的数目。
mtu<字节> 设置网络设备的MTU。
netmask<子网掩码> 设置网络设备的子网掩码。
tunnel<地址> 建立IPv4与IPv6之间的隧道通信地址。
up 启动指定的网络设备。
-broadcast<地址> 将要送往指定地址的数据包当成广播数据包来处理。
-pointopoint<地址> 与指定地址的网络设备建立直接连线,此模式具有保密功能。
-promisc 关闭或启动指定网络设备的promiscuous模式。
[IP地址] 指定网络设备的IP地址。
[网络设备] 指定网络设备的名称。

实例:

  • 显示网络设备信息
代码语言:javascript
复制
[root@LVS ~]# ifconfig
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.100.106  netmask 255.255.255.0  broadcast 192.168.100.255
        inet6 fe80::e65:fc2a:ca83:27d0  prefixlen 64  scopeid 0x20<link>
        ether 00:0c:29:68:45:f4  txqueuelen 1000  (Ethernet)
        RX packets 129442  bytes 20024014 (19.0 MiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 11350  bytes 1422667 (1.3 MiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 1  (Local Loopback)
        RX packets 4362  bytes 452809 (442.1 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 4362  bytes 452809 (442.1 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

virbr0: flags=4099<UP,BROADCAST,MULTICAST>  mtu 1500
        inet 192.168.122.1  netmask 255.255.255.0  broadcast 192.168.122.255
        ether 52:54:00:a4:73:ea  txqueuelen 1000  (Ethernet)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
  • 启动关闭指定网卡
代码语言:javascript
复制
[root@LVS ~]# ifconfig eth0 down

[root@LVS ~]

# ifconfig eth0 up

[root@LVS ~]

#

  • 配置IP地址
代码语言:javascript
复制
[root@LVS ~]# ifconfig ens33 192.168.100.106 netmask 255.255.255.0 broadcast 192.168.100.255

[root@LVS ~]

#

  • 启用和关闭arp协议
代码语言:javascript
复制
 [root@LVS ~]# ifconfig ens33 arp[root@LVS ~]# ifconfig ens33 -arp #关闭后SSH无法连接[root@LVS ~]# 
  • 设置最大传输单元
代码语言:javascript
复制
 [root@LVS ~]# ifconfig ens33 mtu 1500

补:启动和关闭网卡

代码语言:javascript
复制
[root@LVS ~]# ifup ens33

[root@LVS ~]

# ifdown ens33

8.6 netstat

功能:查看网络状态。

语法:

代码语言:javascript
复制
netstat [-acCeFghilMnNoprstuvVwx][-A<网络类型>][--ip]

参数:

代码语言:javascript
复制
-a或--all 显示所有连线中的Socket。
-A<网络类型>或--<网络类型> 列出该网络类型连线中的相关地址。
-c或--continuous 持续列出网络状态。
-C或--cache 显示路由器配置的快取信息。
-e或--extend 显示网络其他相关信息。
-F或--fib 显示FIB。
-g或--groups 显示多重广播功能群组组员名单。
-h或--help 在线帮助。
-i或--interfaces 显示网络界面信息表单。
-l或--listening 显示监控中的服务器的Socket。
-M或--masquerade 显示伪装的网络连线。
-n或--numeric 直接使用IP地址,而不通过域名服务器。
-N或--netlink或--symbolic 显示网络硬件外围设备的符号连接名称。
-o或--timers 显示计时器。
-p或--programs 显示正在使用Socket的程序识别码和程序名称。
-r或--route 显示Routing Table。
-s或--statistice 显示网络工作信息统计表。
-t或--tcp 显示TCP传输协议的连线状况。
-u或--udp 显示UDP传输协议的连线状况。
-v或--verbose 显示指令执行过程。
-V或--version 显示版本信息。
-w或--raw 显示RAW传输协议的连线状况。
-x或--unix 此参数的效果和指定"-A unix"参数相同。
--ip或--inet 此参数的效果和指定"-A inet"参数相同。

实例:

  • 显示详细的网络状况
代码语言:javascript
复制
[root@LVS ~]# netstat -a
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address           Foreign Address         State      
tcp        0      0 0.0.0.0:sunrpc          0.0.0.0:*               LISTEN     
tcp        0      0 LVS:domain              0.0.0.0:*               LISTEN     
tcp        0      0 0.0.0.0:ssh             0.0.0.0:*               LISTEN     
tcp        0      0 localhost:ipp           0.0.0.0:*               LISTEN     
tcp        0      0 localhost:6011          0.0.0.0:*               LISTEN     
tcp        0      0 localhost:6012          0.0.0.0:*               LISTEN     
tcp        0      0 localhost:6013          0.0.0.0:*               LISTEN     
tcp        0      0 localhost:6014          0.0.0.0:*               LISTEN     
  • 显示当前户籍UDP连接状况
代码语言:javascript
复制
[root@LVS ~]# netstat -nu
Active Internet connections (w/o servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State      
udp        0      0 192.168.100.106:59819   111.230.189.174:123     ESTABLISHED
udp        0      0 192.168.100.106:46885   78.46.102.180:123       ESTABLISHED
udp        0      0 192.168.100.106:50997   162.159.200.123:123     ESTABLISHED
udp        0      0 192.168.100.106:39874   108.59.2.24:123         ESTABLISHED

[root@LVS ~]

#

  • 显示UDP端口号的使用情况
代码语言:javascript
复制
[root@LVS ~]# netstat -apu
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name    
udp        0      0 0.0.0.0:mdns            0.0.0.0:*                           588/avahi-daemon: r 
udp        0      0 0.0.0.0:hpoms-dps-lstn  0.0.0.0:*                           21193/dhclient      
udp        0      0 localhost:323           0.0.0.0:*                           572/chronyd         
udp        0      0 LVS:59819               111.230.189.174:ntp     ESTABLISHED 572/chronyd         
udp        0      0 LVS:46885               78.46.102.180:ntp       ESTABLISHED 572/chronyd         
udp        0      0 LVS:50997               162.159.200.123:ntp     ESTABLISHED 572/chronyd         
  • 显示网卡列表
代码语言:javascript
复制
[root@LVS ~]# netstat -i
Kernel Interface table
Iface      MTU    RX-OK RX-ERR RX-DRP RX-OVR    TX-OK TX-ERR TX-DRP TX-OVR Flg
ens33     1500   133114      0      0 0         12200      0      0      0 BMRU
lo       65536     4643      0      0 0          4643      0      0      0 LRU
virbr0    1500        0      0      0 0             0      0      0      0 BMU

[root@LVS ~]

#

  • 显示组播组的关系
代码语言:javascript
复制
[root@LVS ~]# netstat -g
IPv6/IPv4 Group Memberships
Interface       RefCnt Group
--------------- ------ ---------------------
lo              1      224.0.0.1
ens33           1      224.0.0.251
ens33           1      224.0.0.1
virbr0          1      224.0.0.251
virbr0          1      224.0.0.1
  • 显示网络统计信息
代码语言:javascript
复制
[root@LVS ~]# netstat -s
Ip:
    118440 total packets received
    0 forwarded
    0 incoming packets discarded
    20653 incoming packets delivered
    15660 requests sent out
    31 outgoing packets dropped
    28 dropped because of missing route
    2 fragments received ok
    4 fragments created
Icmp:
    90 ICMP messages received
    0 input ICMP message failed.
  • 显示监听的套接口
代码语言:javascript
复制
[root@LVS ~]# netstat -l
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State      
tcp        0      0 0.0.0.0:sunrpc          0.0.0.0:*               LISTEN     
tcp        0      0 LVS:domain              0.0.0.0:*               LISTEN     
tcp        0      0 0.0.0.0:ssh             0.0.0.0:*               LISTEN     
tcp        0      0 localhost:ipp           0.0.0.0:*               LISTEN     
tcp        0      0 localhost:6011          0.0.0.0:*               LISTEN     
tcp        0      0 localhost:6012          0.0.0.0:*               LISTEN     
tcp        0      0 localhost:6013          0.0.0.0:*               LISTEN     
tcp        0      0 localhost:6014          0.0.0.0:*               LISTEN     

九、高级网络操作命令

9.1 ss

功能:查看网络状态。

ss是Socket Statistics的缩写。顾名思义,ss命令可以用来获取socket统计信息,它可以显示和netstat类似的内容。ss的优势在于它能够显示更多更详细的有关TCP和连接状态的信息,而且比netstat更快速更高效。

当服务器的socket连接数量变得非常大时,无论是使用netstat命令还是直接cat /proc/net/tcp,执行速度都会很慢。

ss快的秘诀在于,它利用到了TCP协议栈中tcp_diag。tcp_diag是一个用于分析统计的模块,可以获得Linux 内核中第一手的信息,这就确保了ss的快捷高效。

语法:

代码语言:javascript
复制
ss [ OPTIONS ]
ss [ OPTIONS ] [ FILTER ]

参数:

代码语言:javascript
复制
   -h, --help          this message
   -V, --version       output version information
   -n, --numeric       don't resolve service names
   -r, --resolve       resolve host names
   -a, --all           display all sockets
   -l, --listening     display listening sockets
   -o, --options       show timer information
   -e, --extended      show detailed socket information
   -m, --memory        show socket memory usage
   -p, --processes     show process using socket
   -i, --info          show internal TCP information
   -s, --summary       show socket usage summary
   -b, --bpf           show bpf filter socket information
   -Z, --context       display process SELinux security contexts
   -z, --contexts      display process and socket SELinux security contexts
   -N, --net           switch to the specified network namespace name

   -4, --ipv4          display only IP version 4 sockets
   -6, --ipv6          display only IP version 6 sockets
   -0, --packet        display PACKET sockets
   -t, --tcp           display only TCP sockets
   -u, --udp           display only UDP sockets
   -d, --dccp          display only DCCP sockets
   -w, --raw           display only RAW sockets
   -x, --unix          display only Unix domain sockets
   -f, --family=FAMILY display sockets of type FAMILY

实例:

  • 显示TCP连接
代码语言:javascript
复制
[root@LVS ~]# ss -t -a
State       Recv-Q Send-Q                            Local Address:Port                                             Peer Address:Port                
LISTEN      0      128                                           *:sunrpc                                                      *:*                    
LISTEN      0      5                                 192.168.122.1:domain                                                      *:*                    
LISTEN      0      128                                           *:ssh                                                         *:*                    
LISTEN      0      128                                   127.0.0.1:ipp                                                         *:*                    
LISTEN      0      128                                   127.0.0.1:x11-ssh-offset                                              *:*                    
LISTEN      0      128                                   127.0.0.1:6011                                                        *:*                    
LISTEN      0      128                                   127.0.0.1:6012                                                        *:*                    
LISTEN      0      128                                   127.0.0.1:6013                                                        *:*                    
LISTEN      0      128                                   127.0.0.1:6014                                                        *:*                    
ESTAB       0      0                               192.168.100.106:ssh                                           192.168.100.103:59804                
ESTAB       0      0                               192.168.100.106:ssh                                           192.168.100.103:53121                
ESTAB       0      0                               192.168.100.106:ssh                                           192.168.100.103:59822                
ESTAB       0      52                              192.168.100.106:ssh                                           192.168.100.103:60220                
ESTAB       0      0                               192.168.100.106:ssh                                           192.168.100.103:59744                
LISTEN      0      128                                          :::sunrpc                                                     :::*                    
LISTEN      0      128                                          :::ssh                                                        :::*                    
LISTEN      0      128                                          :::telnet                                                     :::*                    
LISTEN      0      128                                         ::1:ipp                                                        :::*                    
LISTEN      0      128                                         ::1:x11-ssh-offset                                             :::*                    
LISTEN      0      128                                         ::1:6011                                                       :::*                    
LISTEN      0      128                                         ::1:6012                                                       :::*                    
LISTEN      0      128                                         ::1:6013                                                       :::*                    
LISTEN      0      128                                         ::1:6014                                                       :::*                    

[root@LVS ~]

#

9.2 tcpdump

功能:抓包工具

语法:

代码语言:javascript
复制
tcpdump [-adeflnNOpqStvx][-c<数据包数目>][-dd][-ddd][-F<表达文件>][-i<网络界面>][-r<数据包文件>][-s<数据包大小>][-tt][-T<数据包类型>][-vv][-w<数据包文件>][输出数据栏位]

参数:

代码语言:javascript
复制
-a 尝试将网络和广播地址转换成名称。
-c<数据包数目> 收到指定的数据包数目后,就停止进行倾倒操作。
-d 把编译过的数据包编码转换成可阅读的格式,并倾倒到标准输出。
-dd 把编译过的数据包编码转换成C语言的格式,并倾倒到标准输出。
-ddd 把编译过的数据包编码转换成十进制数字的格式,并倾倒到标准输出。
-e 在每列倾倒资料上显示连接层级的文件头。
-f 用数字显示网际网络地址。
-F<表达文件> 指定内含表达方式的文件。
-i<网络界面> 使用指定的网络截面送出数据包。
-l 使用标准输出列的缓冲区。
-n 不把主机的网络地址转换成名字。
-N 不列出域名。
-O 不将数据包编码最佳化。
-p 不让网络界面进入混杂模式。
-q 快速输出,仅列出少数的传输协议信息。
-r<数据包文件> 从指定的文件读取数据包数据。
-s<数据包大小> 设置每个数据包的大小。
-S 用绝对而非相对数值列出TCP关联数。
-t 在每列倾倒资料上不显示时间戳记。
-tt 在每列倾倒资料上显示未经格式化的时间戳记。
-T<数据包类型> 强制将表达方式所指定的数据包转译成设置的数据包类型。
-v 详细显示指令执行过程。
-vv 更详细显示指令执行过程。
-x 用十六进制字码列出数据包资料。
-w<数据包文件> 把数据包数据写入指定的文件。

实例:

  • 显示TCP包信息
代码语言:javascript
复制
[root@LVS ~]# tcpdump
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on virbr0, link-type EN10MB (Ethernet), capture size 65535 bytes
  • 显示指定数量包
代码语言:javascript
复制
[root@LVS ~]# tcpdump -c 10
  • 转换阅读格式
代码语言:javascript
复制
[root@LVS ~]# tcpdump -d
(000) ret      #65535

[root@LVS ~]

#

9.3 nmap

功能:也就是Network Mapper,是Linux下的网络扫描和嗅探工具包。

语法:

代码语言:javascript
复制
nmap [Scan Type(s)] [Options] {target specification}

参数:

代码语言:javascript
复制
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 ports
    Ex: -p22; -p1-65535; -p U:53,111,137,T:21-25,80,139,8080,S:9
  -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 of 
           directories, 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 separted list of script-files or
           script-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>: Specifies
      probe 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
  --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)
  --log-errors: Log errors/warnings to the normal-format output file
  --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.org
  nmap -v -sn 192.168.0.0/16 10.0.0.0/8
  nmap -v -iR 10000 -Pn -p 80

实例:

  • 获取远程主机的系统类型及开放端口
代码语言:javascript
复制
 [root@LVS ~]# nmap -sS -P0 -sV -O 192.168.100.106​Starting Nmap 6.40 ( http://nmap.org ) at 2020-04-16 07:57 CSTNmap scan report for 192.168.100.106 (192.168.100.106)Host is up (0.000064s latency).Not shown: 998 closed portsPORT    STATE SERVICE VERSION22/tcp  open  ssh     OpenSSH 6.6.1 (protocol 2.0)111/tcp open  rpcbind 2-4 (RPC #100000)Device type: general purposeRunning: Linux 3.XOS CPE: cpe:/o:linux:linux_kernel:3OS details: Linux 3.7 - 3.9Network Distance: 0 hops​OS and Service detection performed. Please report any incorrect results at http://nmap.org/submit/ .Nmap done: 1 IP address (1 host up) scanned in 7.91 seconds
代码语言:javascript
复制
这里的 < target > 可以是单一 IP, 或主机名,或域名,或子网
-sS TCP SYN 扫描 (又称半开放,或隐身扫描)
-P0 允许你关闭 ICMP pings.
-sV 打开系统版本检测
-O 尝试识别远程操作系统
其它选项:
-A 同时打开操作系统指纹和版本检测
-v 详细输出扫描情况.
  • 列出开放了指定端口的主机列表
代码语言:javascript
复制
[root@LVS ~]# nmap -sT -p 80 -oG – 192.168.100.* | grep open
80/tcp open  http
  • 在网络寻找所有在线主机
代码语言:javascript
复制
[root@LVS ~]# nmap -sP 192.168.100.*

Starting Nmap 6.40 ( http://nmap.org ) at 2020-04-16 08:06 CST
Nmap scan report for 192.168.100.1 (192.168.100.1)
Host is up (0.0031s latency).
MAC Address: 30:FC:68:35:C8:CC (Unknown)
Nmap scan report for 192.168.100.100 (192.168.100.100)
Host is up (0.058s latency).
MAC Address: 08:EA:40:F9:C8:40 (Unknown)
Nmap scan report for 192.168.100.101 (192.168.100.101)
Host is up (0.00012s latency).
MAC Address: E4:02:9B:9D:9D:24 (Unknown)
Nmap scan report for 192.168.100.103 (192.168.100.103)
Host is up (0.059s latency).
MAC Address: 50:1A:C5:F9:3D:DB (Unknown)
Nmap scan report for 192.168.100.104 (192.168.100.104)
Host is up (0.11s latency).
MAC Address: A4:D1:8C:24:2A:14 (Unknown)
Nmap scan report for 192.168.100.105 (192.168.100.105)
Host is up (0.079s latency).
MAC Address: D8:1C:79:34:87:21 (Unknown)
Nmap scan report for 192.168.100.108 (192.168.100.108)
Host is up (0.14s latency).
MAC Address: 0C:2C:54:14:D4:7F (Unknown)
Nmap scan report for 192.168.100.106 (192.168.100.106)
Host is up.
Nmap done: 256 IP addresses (8 hosts up) scanned in 2.91 seconds

[root@LVS ~]

#

或者这样也行,指定子网

代码语言:javascript
复制
root@LVS ~]# nmap -sP 192.168.100.0/24

Starting Nmap 6.40 ( http://nmap.org ) at 2020-04-16 08:07 CST
Nmap scan report for 192.168.100.1 (192.168.100.1)
Host is up (0.0050s latency).
MAC Address: 30:FC:68:35:C8:CC (Unknown)
Nmap scan report for 192.168.100.100 (192.168.100.100)
Host is up (0.017s latency).
MAC Address: 08:EA:40:F9:C8:40 (Unknown)
Nmap scan report for 192.168.100.101 (192.168.100.101)
Host is up (0.00018s latency).
MAC Address: E4:02:9B:9D:9D:24 (Unknown)
Nmap scan report for 192.168.100.103 (192.168.100.103)
Host is up (0.023s latency).
MAC Address: 50:1A:C5:F9:3D:DB (Unknown)
Nmap scan report for 192.168.100.105 (192.168.100.105)
Host is up (0.21s latency).
MAC Address: D8:1C:79:34:87:21 (Unknown)
Nmap scan report for 192.168.100.106 (192.168.100.106)
Host is up.
Nmap done: 256 IP addresses (6 hosts up) scanned in 3.64 seconds

[root@LVS ~]

#

  • Ping 指定范围内的 IP 地址
代码语言:javascript
复制
 [root@LVS ~]# nmap -sP 192.168.100.100-200​Starting Nmap 6.40 ( http://nmap.org ) at 2020-04-16 08:09 CSTNmap scan report for 192.168.100.100 (192.168.100.100)Host is up (0.043s latency).MAC Address: 08:EA:40:F9:C8:40 (Unknown)Nmap scan report for 192.168.100.101 (192.168.100.101)Host is up (0.00026s latency).MAC Address: E4:02:9B:9D:9D:24 (Unknown)Nmap scan report for 192.168.100.103 (192.168.100.103)Host is up (0.034s latency).MAC Address: 50:1A:C5:F9:3D:DB (Unknown)Nmap scan report for 192.168.100.106 (192.168.100.106)Host is up.Nmap done: 101 IP addresses (4 hosts up) scanned in 1.51 seconds[root@LVS ~]# 
  • 在某段子网上查找未占用的 IP
代码语言:javascript
复制
 [root@LVS ~]# nmap -T4 -sP 192.168.100.0/24 && egrep “00:00:00:00:00:00″ /proc/net/arp​Starting Nmap 6.40 ( http://nmap.org ) at 2020-04-16 08:11 CSTNmap scan report for 192.168.100.1 (192.168.100.1)Host is up (0.0050s latency).MAC Address: 30:FC:68:35:C8:CC (Unknown)Nmap scan report for 192.168.100.100 (192.168.100.100)Host is up (0.11s latency).MAC Address: 08:EA:40:F9:C8:40 (Unknown)Nmap scan report for 192.168.100.101 (192.168.100.101)Host is up (0.00022s latency).MAC Address: E4:02:9B:9D:9D:24 (Unknown)Nmap scan report for 192.168.100.102 (192.168.100.102)Host is up (0.23s latency).MAC Address: 90:AD:F7:1A:21:C2 (Unknown)Nmap scan report for 192.168.100.103 (192.168.100.103)Host is up (0.11s latency).MAC Address: 50:1A:C5:F9:3D:DB (Unknown)Nmap scan report for 192.168.100.105 (192.168.100.105)Host is up (0.038s latency).MAC Address: D8:1C:79:34:87:21 (Unknown)Nmap scan report for 192.168.100.106 (192.168.100.106)Host is up.Nmap done: 256 IP addresses (7 hosts up) scanned in 5.22 seconds[root@LVS ~]# cat /proc/net/arpIP address       HW type     Flags       HW address            Mask     Device192.168.100.101  0x1         0x2         e4:02:9b:9d:9d:24     *        ens33192.168.100.103  0x1         0x2         50:1a:c5:f9:3d:db     *        ens33192.168.100.104  0x1         0x2         a4:d1:8c:24:2a:14     *        ens33192.168.100.108  0x1         0x2         0c:2c:54:14:d4:7f     *        ens33192.168.100.100  0x1         0x2         08:ea:40:f9:c8:40     *        ens33192.168.100.102  0x1         0x2         90:ad:f7:1a:21:c2     *        ens33192.168.100.105  0x1         0x2         d8:1c:79:34:87:21     *        ens33192.168.100.1    0x1         0x2         30:fc:68:35:c8:cc     *        ens33[root@LVS ~]# 
  • 在局域网上扫找 Conficker 蠕虫病毒
代码语言:javascript
复制
[root@LVS ~]# nmap -PN -T4 -p139,445 -n -v –script=smb-check-vulns –script-args safe=1 192.168.100.1-254
  • 扫描网络上的恶意接入点 (rogue APs)
代码语言:javascript
复制
[root@LVS ~]# nmap -A -p1-85,113,443,8080-8100 -T4 –min-hostgroup 50 –max-rtt-timeout 2000 –initial-rtt-timeout 300 –max-retries 3 –host-timeout 2ax-scan-delay 1000 -oA wapscan 192.168.100.0/24
  • 使用诱饵扫描方法来扫描主机端口
代码语言:javascript
复制
[root@LVS ~]# nmap -sS 192.168.100.106 -D 192.168.100.108

Starting Nmap 6.40 ( http://nmap.org ) at 2020-04-16 08:30 CST
Nmap scan report for 192.168.100.106 (192.168.100.106)
Host is up (0.000010s latency).
Not shown: 998 closed ports
PORT    STATE SERVICE
22/tcp  open  ssh
111/tcp open  rpcbind

Nmap done: 1 IP address (1 host up) scanned in 0.13 seconds

[root@LVS ~]

# nmap -sS 192.168.100.107 -D 192.168.100.108 Starting Nmap 6.40 ( http://nmap.org ) at 2020-04-16 08:31 CST Note: Host seems down. If it is really up, but blocking our ping probes, try -Pn Nmap done: 1 IP address (0 hosts up) scanned in 0.44 seconds

[root@LVS ~]

#

  • 显示网络上共有多少台 Linux 及 Win 设备?
代码语言:javascript
复制
[root@LVS ~]# nmap -F -O 192.168.100.1-255 | grep "Running: " > /tmp/os; echo "$(cat /tmp/os | grep Linux | wc -l) Linux device(s)"; echo "$(cat /tmp/os | grep Windows | wc -l) Window(s) device"
RTTVAR has grown to over 2.3 seconds, decreasing to 2.0
RTTVAR has grown to over 2.3 seconds, decreasing to 2.0
RTTVAR has grown to over 2.3 seconds, decreasing to 2.0
RTTVAR has grown to over 2.3 seconds, decreasing to 2.0
RTTVAR has grown to over 2.3 seconds, decreasing to 2.0
RTTVAR has grown to over 2.3 seconds, decreasing to 2.0
RTTVAR has grown to over 2.3 seconds, decreasing to 2.0
1 Linux device(s)
1 Window(s) device

[root@LVS ~]

#

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 8.2 wget
  • 8.3 ping
  • 8.4 route
  • 8.5 ifconfig
  • 8.6 netstat
  • 九、高级网络操作命令
    • 9.1 ss
    • 9.2 tcpdump
    • 9.3 nmap
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档