Article count:922 Read by:3074353

Account Entry

Linux - curl command uses proxy and introduction to proxy types

Latest update time:2024-05-22
    Reads:


Link: https://www.cnblogs.com/panxuejun/p/10574038.html

Sometimes for personal privacy reasons, we want to hide our IP so that the http server cannot record that we have visited it. In this case, we can use a proxy server.
The proxy server (Proxy Server) is a service application that works between the browser and the http server. All http requests passing through the proxy server will be forwarded to the corresponding http server.
Of course, in addition to http that can use proxies, https, ftp, RTSP, pop3 and other protocols can also be accessed using proxies. However, this article introduces proxies that support http and https protocol access.

1. Proxy server classification:

Our commonly used and supported http(s) protocol proxies are mainly divided into two categories: http proxies and socks proxies, see the table below:
Category subcategory Subclass describe
http proxy http proxy
https proxy
transparent proxy The http server knows that the browser uses a proxy and can obtain the original IP address of the browser.
anonymous proxy The http server knows that the browser uses a proxy, but cannot obtain the original IP of the browser;
High Anonymity Proxy The http server does not know that the browser uses a proxy and cannot obtain the original IP of the browser;
SOCKS proxy SOCKS4 Known as a universal
proxy , it supports http
and other protocols
Only TCP applications are supported;
SOCKS4A Support TCP applications; support server-side domain name resolution;
SOCKS5 Supports TCP and UDP applications; supports server-side domain name resolution;
supports multiple authentications; supports IPV6;

2. Linux curl command proxy setting parameters:

The linux curl command can use the following parameters to set the http(s) proxy and socks proxy. Their username, password and authentication method have been set:

parameter usage
-x host:port
-x [protocol://[user:pwd@]host[:port]
--proxy [protocol://[user:pwd@]host[:port]
Use HTTP proxy for access; if the port is not specified, port 8080 is used by default;
protocol defaults to http_proxy, other possible values ​​include:
http_proxy, HTTPS_PROXY, socks4, socks4a, socks5;
such as:
--proxy 8.8.8.8:8080;
-x "http_proxy://aiezu:123@aiezu.com:80"
--socks4 <host[:port]>
--socks4a <host[:port]>
--socks5 <host[:port]>
Use SOCKS4 proxy;
use SOCKS4A proxy; use SOCKS5 proxy ; this parameter will override the "-x" parameter;

--proxy-anyauth
--proxy-basic
--proxy-diges
--proxy-negotiate
--proxy-ntlm
Proxy authentication method, refer to:
--anyauth
--basic
--diges
--negotiate
--ntlm
-U <user:password>
--proxy-user <user:password>
Set the username and password of the agent;


3. Example of setting proxy using Linux curl command:

1. Linux curl command sets http proxy:

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

# 指定http代理IP和端口

curl -x 113.185.19.192:80 http: //aiezu .com /test .php

curl --proxy 113.185.19.192:80 http: //aiezu .com /test .php

#指定为http代理

curl -x http_proxy: //113 .185.19.192:80 http: //aiezu .com /test .php

#指定为https代理

curl -x HTTPS_PROXY: //113 .185.19.192:80 http: //aiezu .com /test .php

#指定代理用户名和密码,basic认证方式

curl -x aiezu:123456@113.185.19.192:80 http: //aiezu .com /test .php

curl -x 113.185.19.192:80 -U aiezu:123456 http: //aiezu .com /test .php

curl -x 113.185.19.192:80 --proxy-user aiezu:123456 http: //aiezu .com /test .php

#指定代理用户名和密码,ntlm认证方式

curl -x 113.185.19.192:80 -U aiezu:123456 --proxy-ntlm http: //aiezu .com /test .php

#指定代理协议、用户名和密码,basic认证方式

curl -x http_proxy: //aiezu :123456@113.185.19.192:80 http: //aiezu .com /test .php

2. Linux curl command sets socks proxy:

1

2

3

4

5

6

7

8

9

10

11

12

13

14

#使用socks4代理,无需认证方式

curl --socks4 122.192.32.76:7280 http: //aiezu .com /test .php

curl -x socks4: //122 .192.32.76:7280 http: //aiezu .com /test .php

#使用socks4a代理,无需认证方式

curl --socks4a 122.192.32.76:7280 http: //aiezu .com /test .php

curl -x socks4a: //122 .192.32.76:7280 http: //aiezu .com /test .php

#使用socks5代理,basic认证方式

curl --socks5 122.192.32.76:7280 -U aiezu:123456 http: //aiezu .com /test .php

curl -x socks5: //aiezu :123456@122.192.32.76:7280 http: //aiezu .com /test .php

#使用socks5代理,basic认证方式,ntlm认证方式

curl -x socks5: //aiezu :123456@122.192.32.76:7280 --proxy-ntlm http: //aiezu .com /test .php

4. Test the anonymity of the agent:

1. Preparation before testing:

Before testing, we first create a PHP page "test.php" in the root directory of the website to output the visitor IP address information received by the http server. The code of the "test.php" test page is as follows:

1

2

3

4

5

6

7

8

9

<?php

$array = array ( 'HTTP_USER_AGENT' , 'HTTP_HOST' , 'HTTP_ACCEPT' , 'PATH' , 'SERVER_SIGNATURE' , 'SERVER_SOFTWARE' , 'SERVER_NAME' , 'SERVER_ADDR' , 'SERVER_PORT' , 'DOCUMENT_ROOT' , 'SERVER_ADMIN' , 'SCRIPT_FILENAME' , 'REMOTE_PORT' , 'GATEWAY_INTERFACE' , 'SERVER_PROTOCOL' , 'REQUEST_METHOD' , 'QUERY_STRING' , 'REQUEST_URI' , 'SCRIPT_NAME' , 'PHP_SELF' , 'REQUEST_TIME' );

//  将 $_SERVER 数组赋予 $srv数组;

$srv = $_SERVER ;

// 释放掉 $srv中不相关的键

foreach ( $array as $name ) {

unset( $srv [ $name ]);

}

print_r( $srv );

After saving "test.php", we then access it without a proxy, or by using a transparent proxy, an anonymous proxy, a high-anonymity proxy, and SOCKS to see the content results output by the page.

2. Test the output results using different agents:

①. Access via linux curl without proxy:

[root@aiezu.com ~]# curl http://aiezu.com/test.php
Array
(
[REMOTE_ADDR] => 114.112.104.126
)

It can be seen that the "REMOTE_ADDR" IP address obtained by the http server is "114.112.104.126", and this IP address is the real IP address of the client lcurl.

②. Use http transparent proxy access through linux curl command:

[root@aiezu.com ~]# curl -x 37.139.9.11:80 http://aiezu.com/test.php
Array
(
[HTTP_VIA] => 1.1 ThunderVPN (squid/3.3.8)
[HTTP_X_FORWARDED_FOR] => 114.112.104.126
[HTTP_CACHE_CONTROL] => max-age=259200
[HTTP_CONNECTION] => keep-alive
[REMOTE_ADDR] => 37.139.9.11
)

It can be seen that the REMOTE_ADDR field becomes the IP address of the proxy server. At the same time, the real IP address can also be obtained from the HTTP_X_FORWARDED_FOR field. There is also an additional "HTTP_VIA" field. It can be seen that the proxy cannot hide the real IP, and it will also allow The http server automatically uses a proxy on the browser side.

③. Use http anonymous proxy access through linux curl command:

[root@aiezu.com ~]# curl -x 60.21.209.114:8080 http://aiezu.com/test.php
Array
(
[HTTP_PROXY_CONNECTION] => Keep-Alive
[REMOTE_ADDR] => 60.21.209.114
)

As can be seen from the above, the REMOTE_ADDR field becomes the IP address of the proxy server, and the response does not contain the original real IP address. However, with the addition of HTTP_PROXY_CONNECTION, it can be judged that a proxy is used, and it can be concluded that this browser client uses Anonymous proxy.

④. Use http high-anonymity proxy access through the linux curl command:

[root@aiezu.com ~]# curl -x 114.232.1.13:8088 http://aiezu.com/test.php
Array
(
[REMOTE_ADDR] => 114.232.1.13
)

This time we were surprised to find that REMOTE_ADDR also became the IP address of the proxy without leaving any residual evidence to prove the use of a proxy. We can conclude that this is the legendary high-anonymity proxy.

④. Use socks5 proxy to access through linux curl command:

[root@aiezu.com ~]# curl --socks5 122.192.32.76:7280 http://aiezu.com/test.phpArray( [REMOTE_ADDR] => 180.96.54.198)

It can be seen that this SOCKS5 proxy is also a high-anonymity proxy.



The spring recruitment has begun. If you are not adequately prepared, it will be difficult to find a good job during the spring recruitment.


I’m sending you a big employment gift package, so you can raid the spring recruitment and find a good job!



Latest articles about

 
EEWorld WeChat Subscription

 
EEWorld WeChat Service Number

 
AutoDevelopers

About Us Customer Service Contact Information Datasheet Sitemap LatestNews

Room 1530, Zhongguancun MOOC Times Building,Block B, 18 Zhongguancun Street, Haidian District,Beijing, China Tel:(010)82350740 Postcode:100190

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号