使用CURLOPT_RESOLVE为给定的主机名+端口*数字组合提供自定义IP地址。

/****************************************************************************                                  _   _ ____  _*  Project                     ___| | | |  _ \| |*                             / __| | | | |_) | |*                            | (__| |_| |  _ <| |___*                             \___|\___/|_| \_\_____|** Copyright (C) 1998 - 2019, Daniel Stenberg, <daniel@haxx.se>, et al.** This software is licensed as described in the file COPYING, which* you should have received as part of this distribution. The terms* are also available at https://curl.haxx.se/docs/copyright.html.** You may opt to use, copy, modify, merge, publish, distribute and/or sell* copies of the Software, and permit persons to whom the Software is* furnished to do so, under the terms of the COPYING file.** This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY* KIND, either express or implied.****************************************************************************/
/* <DESC>* Use CURLOPT_RESOLVE to feed custom IP addresses for given host name + port* number combinations. 使用CURLOPT_RESOLVE为给定的主机名+端口*数字组合提供自定义IP地址。* </DESC>*/
#include <stdio.h>
#include <curl/curl.h>int main(void)
{CURL *curl;CURLcode res = CURLE_OK;/* Each single name resolve string should be written using the formatHOST:PORT:ADDRESS where HOST is the name libcurl will try to resolve,PORT is the port number of the service where libcurl wants to connect tothe HOST and ADDRESS is the numerical IP address   增加HTTP Header*/struct curl_slist *host = curl_slist_append(NULL,"localhost:80:127.0.0.1");curl = curl_easy_init();if(curl) {
//    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.
//    提供特定主机和端口对的自定义地址。 使用此功能,
//        可以使卷曲请求使用指定的地址,并防止使用通常可以正常解析的地址。
//        考虑它是命令行上提供的/ etc / hosts替代方案。 端口号应为主机将用于特定协议的号码。
//        这意味着如果要提供同一主机但不同端口的地址,则需要几个条目。curl_easy_setopt(curl, CURLOPT_RESOLVE, host);curl_easy_setopt(curl, CURLOPT_URL, "http://10.170.6.66");res = curl_easy_perform(curl);/* always cleanup */curl_easy_cleanup(curl);}curl_slist_free_all(host);return (int)res;
}

C语言libcurl:提供特定主机和端口对的自定义地址--resolve相关推荐

  1. c语言为什么提供函数声明机制,通过实战理解C语言精要——函数篇

    本文为作者原创,转载请注明出处,感谢您的阅读与分享,希望本文能让您有所收获. 前言 本篇博客是对C语言函数部分的重点内容和细枝末节通过实战得到的经验的总结精炼,不涵盖C语言函数的全部内容,所有提炼内容 ...

  2. dns提供商主机名_什么是FQDN?它和主机名有区别吗?

    请关注本头条号,每天坚持更新原创干货技术文章. 如需学习视频,请在微信搜索公众号"智传网优"直接开始自助视频学习 1. 前言 本文主要讲解什么是FQDN. 什么是FQDN 2. F ...

  3. wmi服务或wmi提供程序_什么是WMI提供程序主机(WmiPrvSE.exe),为什么使用那么多的CPU?...

    wmi服务或wmi提供程序 The WMI Provider Host process is an important part of Windows, and often runs in the b ...

  4. Python编写masscan+nmap的主机和端口信息收集工具

    masscan使用 linux安装 git clone https://github.com/robertdavidgraham/masscan make 扫描选项 masscan -iL targe ...

  5. Nmap学习——目标主机、端口、操作系统和服务探测以及输出格式

    1.nmap简介 nmap是一个用于网络探测和安全/端口扫描的工具,全称Network Mapper(网络映射器),主要用来快速扫描大型网络,提供目标主机的各类信息,如:目标机的服务类型及状态.端口号 ...

  6. R语言ggplot2进行特定国家或者地区的地图可视化、在地图上标出所有首府城市所在地(plot the locations of the capital cities)

    R语言ggplot2进行特定国家或者地区的地图可视化.在地图上标出所有首府城市所在地(plot the locations of the  capital cities) 目录

  7. R语言保存图片为特定dpi值(分辨率)的图像

    R语言保存图片为特定dpi值(分辨率)的图像 目录 R语言保存图片为特定dpi值(分辨率)的图像 # 保存为特定dpi像素的图像示例1

  8. “可扩展标记语言”(XML) 提供一种描述结构化数据的方法。

    摘要: "可扩展标记语言"(XML) 提供一种描述结构化数据的方法.与主要用于控制数据的显示和外观的 HTML 标记不同,XML 标记用于定义数据本身的结构和数据类型. XML 使 ...

  9. linux uts namespace 提供了主机名和域名的隔离 docker中被用到

    UTS,UNIX Time-sharing System namespace提供了主机名和域名的隔离.能够使得子进程有独立的主机名和域名(hostname),这一特性在Docker容器技术中被用到,使 ...

最新文章

  1. 20172324 2018-2019-1《程序设计与数据结构》实验2报告
  2. Mac如何安装并永久激活PyCharm以及IntelliJ IDEA
  3. golang协程特点
  4. 五十二、Python北京美团汉堡外卖数据分析实战
  5. Mongodb 集群加keyFile认证
  6. You have unstaged changes.
  7. Debian 决定允许无记名投票,候选人Felix Lechner质疑
  8. 可伸缩多线程任务队列
  9. CSS3 实现图片上浮动画
  10. 把CAS部署远程服务器上,在本地client访问CAS会出现无法统一注销的问题
  11. 新浪微博如何批量删除以前发过的微博
  12. 《梦想新大陆》美术研发手札
  13. 个人学习笔记---Linux内存:内存管理的实质
  14. ajax怎么会突然出现401,当jquery ajax遇上401请求
  15. 哈工大数字逻辑与数字系统设计大作业(数字密码锁)
  16. background
  17. Delphi 仿QQ皮肤控件设计与运行效果图
  18. 小学生测验(Java)
  19. 0到π/0到2π,sinⁿx、cosⁿx的定积分
  20. ARM 编译工具keil 和 IAR 命令行编译和下载

热门文章

  1. Kafka集群全部断开,然后重启时报“The broker is trying to join the wrong cluster. Configured zookeeper.connect……”问题
  2. 程序设计与算法----递归之神奇的口袋
  3. Guid.NewGuid().ToString()的几种格式 (转)
  4. 介绍一下Python中webbrowser的用法?
  5. 线程的创建 锁 Threading模块 事件 条件 定时器 队列 线程池 回调函数
  6. jvm 分代回收算法通俗理解
  7. C++中的内联函数和C中的宏定义的区别
  8. 使用数据模板自定义数据显示
  9. SQL注入自动扫描工具中的语句
  10. IE浏览器不能上网的处理办法