Linux网络工具

本文主要介绍Linux系统中常用的网络工具。

1. curl命令

curl 命令行访问URL的工具

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# curl http://www.baidu.com	直接将百度网页的源码输出到屏幕上
# curl http://www.baidu.com –o baidu.html 将百度网页的源码保存起来
# curl -O http://www.linux.com/hello.sh 将hello.sh文件下载下来
# curl -# -O http://www.linux.com/dodo1.JPG 显示下载进度条
# curl -C -O http://www.linux.com/dodo1.JPG 断点续传
# curl -o /dev/null -s -w %{http_code} www.baidu.com 测试网页返回值,非常有用
# curl -o /dev/null -s -w %{http_code}:%{http_connect}:%{content_type}:%{time_namelookup}:%{time_redirect}:%{time_pretransfer}:%{time_connect}:%{time_starttransfer}:%{time_total}:%{speed_download} digdeeply.org
# curl -x 192.168.100.100:1080 http://www.linux.com -x参数是设置代理的
# curl -I http://static.futunn.com/passport/images/global/logo_futunn-b9fab8d8f683775e9c3c5ade78e822ec.png -x 211.162.36.175:80
# curl -I www.sina.com.cn -x 124.42.245.30:80
# curl -I 124.42.245.30
# curl -I 124.42.245.30 -H 'host:www.sina.com.cn'

# curl -s -D header.txt http://www.linux.com -o /dev/null 保存访问网站的header信息
# curl -I http://www.linux.com 在屏幕上显示header信息
# curl -c cookie.txt http://www.linux.com 保存访问网站的cookie信息
# curl -A "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.0)" http://www.linux.com 模仿浏览器
# curl -e "www.abc.com" http://mail.linux.com 伪造referer
# curl -T dodo1.JPG -u 用户名:密码 ftp://www.linux.com/img/ 上传文件
# curl ip.cn
# curl myip.ipip.net
# curl ip.cip.cc

2. nmap命令

Nmap 是一款开放源代码的 网络探测和安全审核的工具。 它的设计目标是快速地扫描大型网络 。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# nmap -sP 192.168.1.0/24				使用ping检测192.168.1.0/24这个网段
# nmap --iflist
# nmap -e eth0 192.168.1.5 扫描ip开放的端口
# nmap 192.168.1.1 -p 1-500 自定义扫描端口
# nmap -sn 192.168.1.0/2 只进行主机发现,不进行端口扫描
# nmap 192.168.1.1 -P0 端口扫描(Pn)
# nmap 192.168.1.1-100 多个ip
# nmap -F 192.168.1.* 多个ip,-F 快速扫描
# nmap -sS 192.168.1.153 Tcp SYN Scan (sS)
# nmap -sT 192.168.1.153 Tcp connect() scan(sT)
# nmap -sU 192.168.1.153 Udp scan(sU)
# nmap -sF 192.168.1.153 FINscan(sF)
# nmap -sV 192.168.1.153 版本检测(sV)
# nmap 192.168.1.153 -p U:22,80,T:21-25,80,139,8080 TCP、UDP端口扫描
# nmap --traceroute www.baidu.com 路由跟踪
# nmap -O 192.168.1.153 操作系统
# nmap -A 192.168.1.153 激进方式扫描,扫描端口和os
# nmap -sV -p 22 -oG grep-output.txt 192.168.1.0/24 输出格式,可检索的
# nmap -sV -p 22 -oA grep-output.txt 192.168.1.0/24 输出格式,-oA所有,可检索的、常规的和XML文件
# nmap -sV -p 22 -oX grep-output.txt 192.168.1.0/24 输出格式,XML
# nmap -sV -p 22 -oN grep-output.txt 192.168.1.0/24 输出格式,常规格式

3. nc命令

(1) 安装

1
# yum install -y nc

(2) 远程拷贝文件

1
2
3
4
server1:
# nc -l 1234 > test.txt
server2:
# nc 192.168.1.3 < test.txt

(3) 传输目录

1
2
3
4
server1:
# nc -l 1234 | tar xzv-
server2:
# tar czv- nginx | nc 192.168.48.47 1234

(4) 简单聊天工具

1
2
3
4
在192.168.1.2上: 
# nc -l 1234
在192.168.1.3上:
# nc 192.168.1.2 1234

(5) 端口扫描

1
# nc -v -w 2 192.168.2.34 -z 21-24

(6) 克隆硬盘或分区

1
2
# nc -l -p 1234 | dd of=/dev/sda
# dd if=/dev/sda | nc 192.168.228.222 1234

4. wget命令

wget是一个下载文件的工具 。

命令格式:
wget [参数] [URL地址 ]

wget下载单个文件

1
# wget http://ftp.gnu.org/gnu/wget/wget-1.16.2.tar.gz

下载并以不同的文件名保存

1
# wget http://ftp.gnu.org/gnu/wget/wget-1.16.2.tar.gz -o wget.tgz

限速下载

1
# wget --limit-rate=300k http://ftp.gnu.org/gnu/wget/wget-1.16.2.tar.gz

断点续传

1
# wget -c http://ftp.gnu.org/gnu/wget/wget-1.16.2.tar.gz

后台下载

1
# wget -b http://ftp.gnu.org/gnu/wget/wget-1.16.2.tar.gz

测试下载链接

1
# wget --spider http://ftp.gnu.org/gnu/wget/wget-1.16.2.tar.gz

复制整个网站(镜像)

1
# wget --mirror --convert-links http://exampledomain.com

访问需要认证的HTTP或FTP页面

1
# wget --user username --password pass URL

指定目录下载

1
# wget -P /home/download http://ftp.gnu.org/gnu/wget/wget-1.16.2.tar.gz

下载目录中的所有文件

1
2
3
4
5
6
7
8
9
10
# wget -r -np -nd http://mirrors.163.com/centos/6/isos/x86_64/
# wget -r -p -np -k http://mirrors.163.com/centos/6/isos/x86_64/
参数说明:
-r, --recursive 递归下载
-k, --convert-links 让下载得到的 HTML 或 CSS 中的链接指向本地文件
-m, --mirror -N -r -l inf --no-remove-listing 的缩写形式
-np, --no-parent 不追溯至父目录
-nd, --no-directories 不创建目录
-l, --level=NUMBER 最大递归深度 (inf 或 0 代表无限制,即全部下载)
-c, --continue 断点续传下载文件

https协议

1
2
# wget https://centos6.iuscommunity.org/ius-release.rpm
# wget https://centos6.iuscommunity.org/ius-release.rpm --no-check-certificate
---------------- The End ----------------