C++获取站点的ip地址
2024-08-23 09:58:05
- #include "stdafx.h"
- #include <winsock2.h>
- #pragma comment (lib,"ws2_32.lib")
- int _tmain(int argc, _TCHAR* argv[])
- {
- p: printf("输入地址:");
- char szHost[256];
- memset(szHost,0,256);
- scanf("%s",szHost);
- unsigned long lAddr = inet_addr(szHost);
- if (lAddr == INADDR_NONE)
- {
- hostent *pHE = gethostbyname(szHost);
- if (!pHE)
- goto p;
- sockaddr_in sa;
- for (int iHost=0;pHE->h_addr_list[iHost];iHost++)
- {
- char *ip;
- unsigned int port;
- memcpy(&sa.sin_addr.s_addr, pHE->h_addr_list[iHost], pHE->h_length);
- ip = inet_ntoa(sa.sin_addr);printf("%s\n",ip);
- }
- }
- goto p;
- }
最新文章
- 2013 duilib入门简明教程 -- 部分bug 2 (14)
- <;<;<; request.getParameterMap()方法
- rxjava源码中的线程知识
- ASP.NET Web API 数据验证
- 设置zookeeper jvm内存
- Linux-Hostname-details
- 实用js+css多级树形展开效果导航菜单
- Web Developer可以做得更多
- eclipse 恢复被删除的文件
- Phonegap 3.0 拍照 出错的说明
- Swift - 使用HTML5进行iOS开发(将HTML5打包成iOS应用)
- 万方数据知识平台 TFHpple +Xpath解析
- angular : direative : scope | 指令scope里的符号@,=
- cpp命名空间
- EOJ3536 求蛇形矩阵每一行的和---找规律
- Java 8新特性探究(四)深入解析日期和时间-JSR310
- python--网络编程requests
- XUbuntu18.04(Bionic河狸)正式发布,系统安装升级记录
- vue双向绑定的时候把遍历的数组转为了字符串,并且再转回去数组进行绑定
- LeetCode 30 Substring with Concatenation of All Words(确定包含所有子串的起始下标)
热门文章
- 第1章jquery选择器
- J2ee项目 编译依赖顺序
- [python学习篇][系统学习][1]python标准库中文、英文网址(一些内建函数,标准库都可以在这里查找)
- [python篇][其他] python博客学习汇总
- HDU-2234 无题I
- 《常见问题集》Maven
- [POI2006] KRA-The Disks (贪心)
- ajax cache enable and ajax concurrency!
- Windows PowerShell Exit Codes
- LeetCode OJ——Minimum Depth of Binary Tree