shell中curl 用户详解
来源:互联网 发布:linux退出系统重新登录 编辑:程序博客网 时间:2024/05/21 11:37
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
##基本用法(配合sed/awk/grep)
$curl http:
//bpsky.net
##下载保存
$curl http:
//bpsky.net > index.html
$curl -o index.html http:
//bpsky.net
$curl -O http:
//bpsky.net/target.tar.gz
##通过代理
$curl -x
123.45
.
67.89
:
1080
-o page.html http:
//bpsky.net
##保存cookie
$curl -x
123.45
.
67.89
:
1080
-o page1.html -D cookie0001.txt http:
//bpsky.net
##使用cookie
$curl -x
123.45
.
67.89
:
1080
-o page1.html -D cookie0002.txt -b cookie0001.txt http:
//bpsky.net
##模仿浏览器
$curl -A
"Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)"
-x
123.45
.
67.89
:
1080
-o page.html -D cookie0001.txt http:
//bpsky.net
##伪造referer
$curl -A
"Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)"
-x
123.45
.
67.89
:
1080
-e
"mail.yahoo.com"
-o page.html -D cookie0001.txt http:
//bpsky.net
##循环下载
$curl -O http:
//cgi2.tky.3web.ne.jp/~zzh/screen[1-10].JPG
##循环(匹配)下载
$curl -O http:
//cgi2.tky.3web.ne.jp/~{zzh,nick}/[001-201].JPG # >like zzh/001.JPG
##循环(引用)下载
$curl -o #2_#
1
.jpg http:
//cgi2.tky.3web.ne.jp/~{zzh,nick}/[001-201].JPG # like >001_zzh.jpg
##断点续传
$curl -c -O http:
//cgi2.tky.3wb.ne.jp/~zzh/screen1.JPG
##分块下载
$curl -r
0
-
10240
-o
"zhao.part1"
http:
//cgi2.tky.3web.ne.jp/~zzh/zhao1.mp3 &\
$curl -r
10241
-
20480
-o
"zhao.part1"
http:
//cgi2.tky.3web.ne.jp/~zzh/zhao1.mp3 &\
$curl -r
20481
-
40960
-o
"zhao.part1"
http:
//cgi2.tky.3web.ne.jp/~zzh/zhao1.mp3 &\
$curl -r
40961
- -o
"zhao.part1"
http:
//cgi2.tky.3web.ne.jp/~zzh/zhao1.mp3
...
$cat zhao.part* > zhao.mp3
##GET 上传
$curl http:
//www.yahoo.com/login.cgi?user=nickwolfe&password=12345
##POST 上传
$curl -d
"user=nickwolfe&password=12345"
http:
//www.yahoo.com/login.cgi
##POST 文件上传
$curl -F upload= $localfile -F $btn_name=$btn_value http:
//cgi2.tky.3web.ne.jp/~zzh/up_file.cgi
一、参数详解
-M/--manual 显示全手动 -n/--netrc 从netrc文件中读取用户名和密码 --netrc-optional 使用 .netrc 或者 URL来覆盖-n --ntlm 使用 HTTP NTLM 身份验证 -N/--no-buffer 禁用缓冲输出 -o/--output 把输出写到该文件中 -O/--remote-name 把输出写到该文件中,保留远程文件的文件名 -p/--proxytunnel 使用HTTP代理 --proxy-anyauth 选择任一代理身份验证方法 --proxy-basic 在代理上使用基本身份验证 --proxy-digest 在代理上使用数字身份验证 --proxy-ntlm 在代理上使用ntlm身份验证 -P/--ftp-port <address> 使用端口地址,而不是使用PASV -Q/--quote <cmd> 文件传输前,发送命令到服务器 -r/--range <range> 检索来自HTTP/1.1或FTP服务器字节范围 --range-file 读取(SSL)的随机文件 -R/--remote-time 在本地生成文件时,保留远程文件时间 --retry <num> 传输出现问题时,重试的次数 --retry-delay <seconds> 传输出现问题时,设置重试间隔时间 --retry-max-time <seconds> 传输出现问题时,设置最大重试时间 -s/--silent 静音模式。不输出任何东西 -S/--show-error 显示错误 --socks4 <host[:port]> 用socks4代理给定主机和端口 --socks5 <host[:port]> 用socks5代理给定主机和端口 -t/--telnet-option <OPT=val> Telnet选项设置 --trace <file> 对指定文件进行debug --trace-ascii <file> Like 跟踪但没有hex输出 --trace-time 跟踪/详细输出时,添加时间戳 -T/--upload-file <file> 上传文件 --url <URL> Spet URL to work with -u/--user <user[:password]> 设置服务器的用户和密码 -U/--proxy-user <user[:password]> 设置代理用户名和密码 -V/--version 显示版本信息 -w/--write-out [format] 什么输出完成后 -x/--proxy <host[:port]> 在给定的端口上使用HTTP代理 -X/--request <command> 指定什么命令 -y/--speed-time 放弃限速所要的时间。默认为30 -Y/--speed-limit 停止传输速度的限制,速度时间'秒 -z/--time-cond 传送时间设置 -0/--http1.0 使用HTTP 1.0 -1/--tlsv1 使用TLSv1(SSL) -2/--sslv2 使用SSLv2的(SSL) -3/--sslv3 使用的SSLv3(SSL) --3p-quote like -Q for the source URL for 3rd party transfer --3p-url 使用url,进行第三方传送 --3p-user 使用用户名和密码,进行第三方传送 -4/--ipv4 使用IP4 -6/--ipv6 使用IP6 -#/--progress-bar 用进度条显示当前的传送状态二,常用curl实例
[root@10.10.90.97 ~]# curl -o home.html http://www.sina.com.cn
2,用-O(大写的),后面的url要具体到某个文件,不然抓不下来。我们还可以用正则来抓取东西
[root@10.10.90.97 ~]# curl -O http://www.it415.com/czxt/linux/25002_3.html
3,模拟表单信息,模拟登录,保存cookie信息
[root@10.10.90.97 ~]# curl -c ./cookie_c.txt -F log=aaaa -F pwd=****** http://blog.51yip.com/wp-login.php
4,模拟表单信息,模拟登录,保存头信息
[root@10.10.90.97 ~]# curl -D ./cookie_D.txt -F log=aaaa -F pwd=****** http://blog.51yip.com/wp-login.php
-c(小写)产生的cookie和-D里面的cookie是不一样的。
5,使用cookie文件
[root@10.10.90.97 ~]# curl -b ./cookie_c.txt http://blog.51yip.com/wp-admin
6,断点续传,-C(大写的)
[root@10.10.90.97 ~]# curl -C -O http://www.sina.com.cn
7,传送数据,最好用登录页面测试,因为你传值过去后,curl回抓数据,你可以看到你传值有没有成功
[root@10.10.90.97 ~]# curl -d log=aaaa http://blog.51yip.com/wp-login.php
8,显示抓取错误
[root@10.10.90.97 ~]# curl -f http://www.sina.com.cn/asdf
curl: (22) The requested URL returned error: 404
[root@10.10.90.97 ~]# curl http://www.sina.com.cn/asdf
<HTML><HEAD><TITLE>404,not found</TITLE>
。。。。。。。。。。。。
9,伪造来源地址,有的网站会判断,请求来源地址
[root@10.10.90.97 ~]# curl -e http://localhost http://www.sina.com.cn
10,当我们经常用curl去搞人家东西的时候,人家会把你的IP给屏蔽掉的,这个时候,我们可以用代理
[root@10.10.90.97 ~]# curl -x 10.10.90.83:80 -o home.html http://www.sina.com.cn
11,比较大的东西,我们可以分段下载
[root@10.10.90.97 ~]# curl -r 0-100 -o img.part1 http://i2.f.itc.cn/thumb/180/bj/6018/b_60178154.jpg
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 101 100 101 0 0 1926 0 --:--:-- --:--:-- --:--:-- 0
[root@10.10.90.97 ~]# curl -r 100-200 -o img.part2 http://i2.f.itc.cn/thumb/180/bj/6018/b_60178154.jpg
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 101 100 101 0 0 3498 0 --:--:-- --:--:-- --:--:-- 98k
[root@10.10.90.97 ~]# curl -r 200- -o img.part3 http://i2.f.itc.cn/thumb/180/bj/6018/b_60178154.jpg
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 13515 100 13515 0 0 154k 0 --:--:-- --:--:-- --:--:-- 280k
[root@10.10.90.97 ~]# ll |grep img.part
-rw-r--r-- 1 root root 101 Jan 24 10:59 img.part1
-rw-r--r-- 1 root root 101 Jan 24 11:00 img.part2
-rw-r--r-- 1 root root 13515 Jan 24 11:00 img.part3
用的时候,把他们cat一下就OK了,cat img.part* >img.jpg
12,不显示下载进度信息
[root@10.10.90.97 ~]# curl -s -o aaa.jpg
13,显示下载进度条
[root@10.10.90.97 ~]# curl -# -O http://www.it415.com/czxt/linux/25002_3.html
######################################################################## 100.0%
14,通过ftp下载文件
[root@10.10.90.97 ~]# curl -u 用户名:密码 -O http://blog.51yip.com/demo/curtain/bbstudy_files/style.css
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
101 1934 101 1934 0 0 3184 0 --:--:-- --:--:-- --:--:-- 7136
或者用下面的方式
[root@10.10.90.97 ~]# curl -O ftp://xukai:test@192.168.242.144:21/www/focus/enhouse/index.php
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 87518 100 87518 0 0 2312k 0 --:--:-- --:--:-- --:--:-- 11.5M
15,通过ftp上传
[root@10.10.90.97 ~]# curl -T xukai.php ftp://xukai:test@192.168.242.144:21/www/focus/enhouse/
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 87518 0 0 100 87518 0 2040k --:--:-- --:--:-- --:--:-- 8901k
使用事例:
#!/bin/bash
2 while read LINE
3 do
4 curl="$LINE"
5 echo -n "$LINE "
6 /usr/bin/curl -s -o /dev/null -w %{http_code}"\\n" $curl
7 if [ "$http_code" == "200" ];then
8 echo "$LINE 请求失败"
9 fi
10 done < a.log
2 while read LINE
3 do
4 curl="$LINE"
5 echo -n "$LINE "
6 /usr/bin/curl -s -o /dev/null -w %{http_code}"\\n" $curl
7 if [ "$http_code" == "200" ];then
8 echo "$LINE 请求失败"
9 fi
10 done < a.log
a.log的内容如下:
1 http://10.10.10.30:51002/clearUserCache4Redis?userId=121
2 http://10.10.10.30:51002/clearUserCache4Redis?userId=123123
3 http://10.10.10.30:51002/clearUserCache4Redis?userId=12312312
4 http://10.10.10.30:51002/clearUserCache4Redis?userId=12312312
5 http://10.10.10.30:51002/clearUserCache4Redis?userId=123123
~
2 http://10.10.10.30:51002/clearUserCache4Redis?userId=123123
3 http://10.10.10.30:51002/clearUserCache4Redis?userId=12312312
4 http://10.10.10.30:51002/clearUserCache4Redis?userId=12312312
5 http://10.10.10.30:51002/clearUserCache4Redis?userId=123123
~
- shell中curl 用户详解
- shell中curl 用户详解
- shell中curl 用法详解 (二)
- shell命令行工具curl详解
- linux 中curl命令详解
- php中curl的详解
- php中curl的详解
- Linux Shell脚本编程--curl命令详解
- Linux Shell脚本编程--curl命令详解
- Linux Shell脚本编程--curl命令详解
- Linux Shell脚本编程--curl命令详解
- Linux Shell脚本编程--curl命令详解
- Linux Shell脚本编程--curl命令详解
- 909422229_Linux Shell脚本编程--curl命令详解
- Linux Shell脚本编程--curl命令详解
- curl中curl_easy_setopt的CURLoption参数详解
- php中curl的参数详解
- curl库中curl_easy_setopt函数详解
- 一步一步学android OpenGL ES2.0编程(2)
- 友善之臂使用
- 教您如何安装使用Mplayer(linux)
- 动态规划优化 最长上升子序列 详解
- 设置 NSZombieEnabled 定位 EXC_BAD_ACCESS 错误
- shell中curl 用户详解
- C++ 命名
- linux 修改时间 date
- Spring3.1.1 quartz1.8.6 定时器配置
- html5之本地存储—JSON对象的使用
- JS实现Map
- NOSQL简介
- 2.1 内置数据类型
- JUnit的使用和常用注解