curl 에서 도메인을 특정 IP로 접속하도록 설정 --resolve

1
curl --help  내용중

     --resolve <host:port:address> Resolve the host+port to this address

*. port 를 0으로 할 경우 모든 포트로 IP변경 가능
=> 이거 잘못됨. 안되더라.



https://docs.oracle.com/cd/E88353_01/html/E37839/curl-1.html
       --resolve <host:port:address[,address]...>
              Provide  a  custom  address  for  a specific host and port pair.
              Using this, you can make the curl requests(s)  use  a  specified
              address  and  prevent the otherwise normally resolved address to
              be used. Consider it a sort of /etc/hosts  alternative  provided
              on  the  command line. The port number should be the number used
              for the specific protocol the host will be used  for.  It  means
              you  need several entries if you want to provide address for the
              same host but different ports.

              The provided address set by this option will be used even if -4,
              --ipv4 or -6, --ipv6 is set to make curl use another IP version.

              Support for providing the IP address within [brackets] was added
              in 7.57.0.

              Support for providing multiple IP addresses per entry was  added
              in 7.59.0.

              This  option  can  be  used many times to add many host names to
              resolve.

              Added in 7.21.3.

-------=--------
테스트

www.naver.com는  223.130.200.104,  223.130.200.107 의 두개의 IP를 가짐(라운드 로빈 DNS)
즉, 저 두 IP중 랜덤으로 접속 됨.

이를 임의로 IP고정 접속해서 가져오도록 하는 방법

$ curl --resolve www.naver.com:443:223.130.200.107 https://www.naver.com|wc -l
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  205k    0  205k    0     0  3504k      0 --:--:-- --:--:-- --:--:-- 3550k
3222
=> OK

$ curl --resolve www.naver.com:443:223.130.200.104 https://www.naver.com|wc -l
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  205k    0  205k    0     0  3307k      0 --:--:-- --:--:-- --:--:-- 3376k
3223
=> OK

$ curl --resolve www.naver.com:443:127.0.0.1 https://www.naver.com|wc -l
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:--  0:00:02 --:--:--     0
curl: (7) Failed to connect to www.naver.com port 443 after 2036 ms: Connection refused
0
=> ERROR
로컬로 www.naver.com 으로 요청해서 에러남. 아파치를 띄우고 www.naver.com 을 설정해 놨다면 응답을 할 것임.


-------------------------------------------
테스트 할 때 hosts 파일을 수정 안하고 테스트 할 수 있다는 이야기.

댓글
  • No Nickname
    No Comment
  • 권한이 없습니다.
    {{m_row.m_nick}}
    -
목록형 📅 달력형