常用网络测试工具使用方法
-
iperf3
服务端: iperf3 -s -i 1 -p 1234
客户端(TCP): iperf3 -c 192.0.8.11 -i 1 -p 1234 -t 60
客户端(UDP):iperf3 -u -c 10.10.2.20 -p 1234 -i 1 -t 10 -b 100M
-
nuttcp
服务端:nuttcp -S
客户端(TCP): nuttcp -T30 -p5001 -w4m -i1 [server IP address]
客户端(UDP):nuttcp -T30 -u -p5001 -w4m -R100M -i1 [server IP address]
-
nc
服务端:nc -ul -p 70
客户端:nc -u IP 70
-
抓包tcpdump
tcpdump -i eth0 port 80
tcpdump -i eth0 -enn -v
tcpdump -i eth0 icmp -w xxx.cap
-
python快速启动http服务
ipv4:python -m SimpleHTTPServer 80
ipv6:python -c "import socket,SocketServer,CGIHTTPServer;SocketServer.TCPServer.address_family=socket.AF_INET6;CGIHTTPServer.test()" 80
- 使用脚本起https服务
1 import BaseHTTPServer 2 import SimpleHTTPServer 3 import os 4 import socket 5 import ssl 6 #import SocketServer 7 #import CGIHTTPServer 8 9 script_home = os.path.dirname(os.path.abspath(__file__)) 10 #SocketServer.TCPServer.address_family = socket.AF_INET6 11 ip = "2008:5be8::12" 12 port = 443 13 14 def main(): 15 print ("simple https server, address:%s:%d, document root:%s" % (ip, port, script_home)) 16 17 httpd = BaseHTTPServer.HTTPServer(('2008:5be8::12', port), SimpleHTTPServer.SimpleHTTPRequestHandler) 18 httpd.socket = ssl.wrap_socket(httpd.socket, certfile='./server.pem', server_side=True) 19 httpd.serve_forever() 20 21 if __name__ == '__main__': 22 os.chdir(script_home) 23 main()
- 使用nginx起https服务
(1)在/etc/nginx目录下新建ssl目录,将文件server.crt,server.key拷贝至/etc/nginx/ssl目录下;
(2)将/etc/nginx/nginx.conf文件新增ssl相关配置项,如下所示:
server { listen 443 ssl http2 default_server; listen [::]:443 ssl http2 default_server; server_name _; root /usr/share/nginx/html; ssl_certificate "/etc/nginx/ssl/server.crt"; ssl_certificate_key "/etc/nginx/ssl/server.key"; ssl_session_cache shared:SSL:1m; ssl_session_timeout 10m; ssl_ciphers HIGH:!aNULL:!MD5; ssl_prefer_server_ciphers on; # Load configuration files for the default server block. include /etc/nginx/default.d/*.conf; location / { } error_page 404 /404.html; location = /40x.html { } error_page 500 502 503 504 /50x.html; location = /50x.html { } }
(3)启动nginx服务,执行:
systemctl start nginx
(4)在浏览器中访问https://【nginx服务器IP】:443
- fio测试磁盘读写速率
读: fio -filename=/dev/sdb -direct=1 -iodepth 1 -thread -rw=read -ioengine=psync -bs=4k -size=10G -numjobs=10 -runtime=300 -group_reporting -name=mytest
写:fio -filename=/dev/sdb -direct=1 -iodepth 1 -thread -rw=write -ioengine=psync -bs=4k -size=10G -numjobs=10 -runtime=300 -group_reporting -name=mytest
随机读写:fio -filename=/dev/vdb -direct=1 -ioengine=libaio -iodepth=32 -bs=8k -rw=randrw -numjobs=1 -runtime=300 -name=test1 -group_reporting -name=mytest
- 发送UDP协议包脚本
(1)client端
import socket s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) addr = ("1.1.1.6", 2345) send_msg = "q" s.sendto(send_msg.encode("utf-8"), addr) response, addr = s.recvfrom(1024) print(response.decode()) print("Receive from %s:%s" % addr) s.close()
(2)server端
import socket s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) s.bind(("2.2.2.2", 2345)) print("UDP bound on port 2345...") while True: data, addr = s.recvfrom(1024) print("Receive from %s:%s" % addr) if data == "q": s.sendto("Good bye!\n", addr) break