黑白格子

  • 首页
  • 所有文章
  • 文章分类
  • 关于页面
  • 友链

  • 搜索
随笔 脚本 Shell MAC IE SSL iptables 网络 k8s docker ubuntu web 镜像 Nginx Linux Windows cloud-init

记几个Curl工具使用技巧

发表于 2020-05-11 | 分类于 Linux | 0 | 阅读次数 268
1. 输出内容自动换行:
curl  -w "\n"  https://www.seekerhcl.cn/

2. 指定网卡作为出口:
curl --interface eth0 ip.sb
或
curl --int 192.168.0.10 ip.sb (此处IP是网卡对应IP地址)

3. 打印请求站点的耗时情况:
curl -o /dev/null -s -w %{http_code}::%{time_namelookup}::%{time_connect}::%{time_starttransfer}::%{time_total}::%{speed_download}"\n" https://www.seekerhcl.cn/

-o:把curl 返回的html、js 输出至回收站[ /dev/null]
-s:去掉所有状态
-w:按照后面的格式写出rt
--connect-timeout:指定tcp连接超时时间
-m:指定数据传输超时时间
http_code:状态码
time_namelookup:DNS 解析域名www.seekerhcl.cn的时间,单位为秒,如果测试的地址为IP,这里耗时即为0
time_commect:client 和 server 端建立 TCP 连接的时间
time_starttransfer:从 client 发出请求;到 web server 响应第一个字节的时间
time_total:client 发出请求;到 web server 发送回所有的相应数据的时间
speed_download:下载速度,单位 byte/s
shell> cat curl.format
time_namelookup:    %{time_namelookup}\n
time_connect:       %{time_connect}\n
time_appconnect:    %{time_appconnect}\n
time_pretransfer:   %{time_pretransfer}\n
time_redirect:      %{time_redirect}\n
time_starttransfer: %{time_starttransfer}\n
time_total:         %{time_total}\n

shell> curl -so /dev/null -w @curl.format https://www.seekerhcl.cn/
time_namelookup:    0.004029
time_connect:       0.014525
time_appconnect:    0.048664
time_pretransfer:   0.048708
time_redirect:      0.000000
time_starttransfer: 0.060849
time_total:         0.060921


4. GET、POST 提交数据
-d 等价 --data

GET:
curl https://www.seekerhcl.cn/

POST:
curl -X POST --data 'keyword=test' https://www.seekerhcl.cn/
curl -X POST --data '{"message": "one"}' https://www.seekerhcl.cn/

5. 模拟特定请求方法
GET方式,不加参数默认为GET方式
curl -Iv -X GET https://www.seekerhcl.cn/

HEAD方式, 参数 -X HEAD
curl -Iv -X HEAD https://www.seekerhcl.cn/

image.png


6. 绑定host访问站点
6.1 使用 -x 参数,通过HTTP代理方式
#弊端是仅限于访问http站点

curl -IvL http://test.seekerhcl.cn -x 123.206.14.147:80

image.png

6.2 指定HOST字段访问
#弊端是仅限于访问http站点
curl -IvL http://123.206.14.147 -H 'Host:test.seekerhcl.cn'

image.png

6.3 使用 --resolve 参数,指定解析记录来访问
# --resolve 参数格式
# --resolve <host:port:address[,address]...>
curl -IL --resolve test.seekerhcl.cn:443:123.206.14.147 https://test.seekerhcl.cn

image.png

  • 本文作者: 黑白格子
  • 本文链接: https://www.clhuang.cn/?p=15
  • 版权声明: 本博客所有文章除特别声明外,均采用CC BY-NC-SA 4.0 许可协议。转载请注明出处!
# 随笔 # 脚本 # Shell # MAC # IE # SSL # iptables # 网络 # k8s # docker # ubuntu # web # 镜像 # Nginx # Linux # Windows # cloud-init
CentOS7修改默认启动内核
CentOS7修改默认启动内核
黑白格子

黑白格子

54 日志
11 分类
17 标签
Creative Commons
0%
© 2021 黑白格子
主题 - NexT.Mist
网站已稳定运行:
陕ICP备16020191号