- 浏览: 375446 次
- 性别:
- 来自: 苏州
-
文章分类
- 全部博客 (335)
- C++ (190)
- 设计模式 (43)
- 数据库技术 (5)
- 网络编程 (11)
- 自动化测试 (6)
- Linux (13)
- OpenSSL (10)
- MS Crypt API (5)
- SCM (2)
- English (4)
- Android (10)
- EMV规范 (1)
- Saturn Platform (0)
- C (10)
- SQL (2)
- ASP.NET (3)
- 英语口语学习 (3)
- 调试工具 (21)
- 编译技术 (5)
- UML (1)
- 项目管理 (5)
- 敏捷开发 (2)
- Http Server (6)
- 代码审查、代码分析 (5)
- 面试基础 (10)
- 重点知识 (16)
- STL (6)
- Efficient C++资料 (8)
- 数据结构和算法 (7)
- 读书笔记 (0)
- 开源项目 (4)
- 多线程 (2)
- Console App (6)
- 个人开源项目 (4)
- IBM DevelopWorks (4)
- Java (16)
- 内存泄漏相关调试和检测 (13)
- 软件测试相关技术 (2)
- C# (11)
- Apple Related (1)
- 软件测试和管理 (2)
- EMV (1)
- Python (1)
- Node.js (6)
- JavaScript (5)
- VUE (1)
- Frontend (1)
- Backend (4)
- RESTful API (3)
- Firebase (3)
最新评论
-
u013189503:
来个密码吧
[C++][Logging] 项目中写日志模块的实现 -
wyf_vc:
来个密码啊!!
[C++][Logging] 项目中写日志模块的实现
发现《Windows网络编程技术》中还是有不少很不错的东西哦,比如说类似Ipconfig的demo。贴出来学习一下。
#include <windows.h> #include <iphlpapi.h> #include <stdio.h> #include <time.h> void main(void) { DWORD Err; PFIXED_INFO pFixedInfo; DWORD FixedInfoSize = 0; PIP_ADAPTER_INFO pAdapterInfo, pAdapt; DWORD AdapterInfoSize; PIP_ADDR_STRING pAddrStr; // // Get the main IP configuration information for this machine using a FIXED_INFO structure // if ((Err = GetNetworkParams(NULL, &FixedInfoSize)) != 0) { if (Err != ERROR_BUFFER_OVERFLOW) { printf("GetNetworkParams sizing failed with error %d\n", Err); return; } } // Allocate memory from sizing information if ((pFixedInfo = (PFIXED_INFO) GlobalAlloc(GPTR, FixedInfoSize)) == NULL) { printf("Memory allocation error\n"); return; } if ((Err = GetNetworkParams(pFixedInfo, &FixedInfoSize)) == 0) { printf("\tHost Name . . . . . . . . . : %s\n", pFixedInfo->HostName); printf("\tDNS Servers . . . . . . . . : %s\n", pFixedInfo->DnsServerList.IpAddress.String); pAddrStr = pFixedInfo->DnsServerList.Next; while(pAddrStr) { printf("%52s\n", pAddrStr->IpAddress.String); pAddrStr = pAddrStr->Next; } printf("\tNode Type . . . . . . . . . : "); switch (pFixedInfo->NodeType) { case 1: printf("%s\n", "Broadcast"); break; case 2: printf("%s\n", "Peer to peer"); break; case 4: printf("%s\n", "Mixed"); break; case 8: printf("%s\n", "Hybrid"); break; default: printf("\n"); } printf("\tNetBIOS Scope ID. . . . . . : %s\n", pFixedInfo->ScopeId); printf("\tIP Routing Enabled. . . . . : %s\n", (pFixedInfo->EnableRouting ? "yes" : "no")); printf("\tWINS Proxy Enabled. . . . . : %s\n", (pFixedInfo->EnableProxy ? "yes" : "no")); printf("\tNetBIOS Resolution Uses DNS : %s\n", (pFixedInfo->EnableDns ? "yes" : "no")); } else { printf("GetNetworkParams failed with error %d\n", Err); return; } // // Enumerate all of the adapter specific information using the IP_ADAPTER_INFO structure. // Note: IP_ADAPTER_INFO contains a linked list of adapter entries. // AdapterInfoSize = 0; if ((Err = GetAdaptersInfo(NULL, &AdapterInfoSize)) != 0) { if (Err != ERROR_BUFFER_OVERFLOW) { printf("GetAdaptersInfo sizing failed with error %d\n", Err); return; } } // Allocate memory from sizing information if ((pAdapterInfo = (PIP_ADAPTER_INFO) GlobalAlloc(GPTR, AdapterInfoSize)) == NULL) { printf("Memory allocation error\n"); return; } // Get actual adapter information if ((Err = GetAdaptersInfo(pAdapterInfo, &AdapterInfoSize)) != 0) { printf("GetAdaptersInfo failed with error %d\n", Err); return; } pAdapt = pAdapterInfo; while (pAdapt) { switch (pAdapt->Type) { case MIB_IF_TYPE_ETHERNET: printf("\nEthernet adapter "); break; case MIB_IF_TYPE_TOKENRING: printf("\nToken Ring adapter "); break; case MIB_IF_TYPE_FDDI: printf("\nFDDI adapter "); break; case MIB_IF_TYPE_PPP: printf("\nPPP adapter "); break; case MIB_IF_TYPE_LOOPBACK: printf("\nLoopback adapter "); break; case MIB_IF_TYPE_SLIP: printf("\nSlip adapter "); break; case MIB_IF_TYPE_OTHER: default: printf("\nOther adapter "); } printf("%s:\n\n", pAdapt->AdapterName); printf("\tDescription . . . . . . . . : %s\n", pAdapt->Description); printf("\tPhysical Address. . . . . . : "); for (UINT i=0; i<pAdapt->AddressLength; i++) { if (i == (pAdapt->AddressLength - 1)) printf("%.2X\n",(int)pAdapt->Address[i]); else printf("%.2X-",(int)pAdapt->Address[i]); } printf("\tDHCP Enabled. . . . . . . . : %s\n", (pAdapt->DhcpEnabled ? "yes" : "no")); pAddrStr = &(pAdapt->IpAddressList); while(pAddrStr) { printf("\tIP Address. . . . . . . . . : %s\n", pAddrStr->IpAddress.String); printf("\tSubnet Mask . . . . . . . . : %s\n", pAddrStr->IpMask.String); pAddrStr = pAddrStr->Next; } printf("\tDefault Gateway . . . . . . : %s\n", pAdapt->GatewayList.IpAddress.String); pAddrStr = pAdapt->GatewayList.Next; while(pAddrStr) { printf("%52s\n", pAddrStr->IpAddress.String); pAddrStr = pAddrStr->Next; } printf("\tDHCP Server . . . . . . . . : %s\n", pAdapt->DhcpServer.IpAddress.String); printf("\tPrimary WINS Server . . . . : %s\n", pAdapt->PrimaryWinsServer.IpAddress.String); printf("\tSecondary WINS Server . . . : %s\n", pAdapt->SecondaryWinsServer.IpAddress.String); struct tm *newtime; // Display coordinated universal time - GMT newtime = gmtime(&pAdapt->LeaseObtained); printf( "\tLease Obtained. . . . . . . : %s", asctime( newtime ) ); newtime = gmtime(&pAdapt->LeaseExpires); printf( "\tLease Expires . . . . . . . : %s", asctime( newtime ) ); pAdapt = pAdapt->Next; } }
- ipconfig.zip (18.1 KB)
- 下载次数: 1
发表评论
-
[Python][网络爬虫]
2020-09-28 16:36 0#!/usr/bin/python #coding: U ... -
[轉]网络七层协议
2019-03-20 12:21 350应用层 与其它计算机 ... -
[转]C++验证IP是否可以PING通
2018-10-30 17:54 1354https://www.cnblogs.com/guoyz13 ... -
C++实现ping功能
2017-04-18 11:21 2192基础知识 ping的过程是向目的IP发送一个type=8的I ... -
socket编程的select模型
2016-07-11 09:20 579转自 http://www.cnblogs.com/Rasca ... -
HTTPS工作原理和TCP握手机制
2016-07-08 10:58 774转自 http://www.admin5.com/ar ... -
accept是又产生一个Socket端口吗?
2016-07-07 09:28 990转自 http://blog.csdn.net/han ... -
C++ Socket Class for Windows
2016-07-06 11:28 815转自 http://www.adp-gmbh.ch/win/m ... -
Socket通信原理探讨(C++为例)
2016-07-06 10:59 652转自 http://www.cnblogs.com/f ... -
IOCP模型与网络编程
2016-06-15 11:04 802转自http://blog.csdn.net/neic ... -
[转]基于Windows Socket 的网络通信中的心跳机制原理
2016-07-21 16:18 1740http://blog.sina.com.cn/s/blog_ ...
相关推荐
- 实现`ipconfig`功能,我们需要了解Winsock(Windows Socket)API,它是Windows下的网络编程接口。 3. Winsock API: - 使用Winsock API可以访问底层网络协议栈,获取网络接口的信息。 - 关键函数包括`...
在Windows系统中,可以使用命令行工具`ipconfig/all`来查看本机的IP配置信息。找到“IPv4 地址”或“IPv6 地址”,这些就是可以用于网络通信的IP地址。在客户端程序中,需要将这些IP地址替换到`client.cpp`中的相应...
- **特点**:C++ Builder具有直观的界面设计工具、高效的编译器以及强大的调试功能。 #### 2. 文件与目录操作 - **知识点**:C++ Builder提供了一系列API来处理文件和目录的操作,包括文件的创建、删除、复制,以及...
在C++中,你可以根据需求选择不同的软件框架来实现socket通信。例如,你可以创建控制台应用程序,它只包含一个黑窗口,没有预设的用户界面。另一种选择是Windows应用程序,它允许你利用Windows API创建带有图形界面...
以下是一个简单的C++程序,它使用系统调用执行`ifconfig`(在Unix-like系统)或`ipconfig`(在Windows系统)命令,并解析输出以获取IP地址: ```cpp #include #include #include #include #include std::...
由于实验要求不使用MFC的Csocket类库和C++ Builder,因此需要直接操作Win32 Socket API,这将涉及更多的网络协议细节和错误处理。 实验的挑战在于设计一个自定义的FTP协议,包括应用层PDU格式和握手方式。对于有更...
在Windows中,可以通过多种方式获取网络连接的状态和配置信息,包括使用命令行工具(如`ipconfig`)和编程接口(如Windows Socket API, WMI - Windows Management Instrumentation)。`ipconfig`命令是最直接的方法...
获取IP地址的方法多种多样,如通过命令行工具(Windows下的`ipconfig`,Linux或MacOS下的`ifconfig`)或者网络编程接口(如Python的socket库)。 2. 硬盘ID:硬盘ID通常指的是硬盘的序列号,它是每个硬盘出厂时被...
- 在Python中,可以使用`socket.gethostbyname(socket.gethostname())`来获取IP地址,`socket.gethostname()`获取机器名。 - C/C++开发者可以使用`gethostname()`和`getaddrinfo()`函数来获取这些信息。 总的来说...
- C++:利用POSIX或Windows API,如`sys/sysinfo.h`(Linux)或`GetSystemInfo`(Windows)。 5. **网络设备参数**: - IP地址和子网掩码:通过`ifconfig`(Linux、Mac)或`ipconfig`(Windows)命令。 - 网络...
在Windows操作系统中,你可以通过以下方法获取计算机名称: 1. 打开“控制面板” -> “系统和安全” -> “系统”,在弹出的窗口中可以看到“计算机名/域/工作组”下的计算机名。 2. 使用命令行工具“cmd”,输入`...
- Windows命令行:使用`ipconfig`命令可以查看本机所有网络接口的IP地址,包括IPv4和IPv6。 - Unix/Linux终端:使用`ifconfig`(较旧系统)或`ip addr show`(较新系统)命令来查看IP信息。 - 通过编程语言:例如...
- **Python**:可以使用`socket`库中的`gethostbyname()`或`getaddrinfo()`函数来获取IP地址。 - **Java**:通过`java.net.NetworkInterface`和`java.net.InetAddress`类,遍历所有网络接口并获取IP。 - **C#**:...
可以使用命令行工具如`ipconfig`(Windows)或`ifconfig`(Linux/Mac)获取本地IP地址,端口号一般自定义,但要确保不与其他服务冲突,常用的是1024-49151之间的非保留端口。 5. **调试步骤**: - **创建服务器端*...
在Windows系统中,可以使用命令行工具如`ipconfig /all`来查看所有网卡的详细信息,包括MAC地址(物理地址)和IPv6地址。在Linux系统中,可以使用`ifconfig`或`ip addr show`命令来获取类似信息。在Unix-like系统中...
- 选择合适的操作系统(如Windows 2000 Advanced Server)。 - 配置虚拟机参数,包括内存大小、处理器数量等。 2. **配置虚拟机**: - 使用“File”菜单中的“Open”选项加载操作系统镜像文件。 - 启动两个...
在Windows系统中,可以通过命令行工具“cmd”来获取IP地址: 1. 打开命令提示符(按Win+R键,输入cmd并回车)。 2. 输入命令`ipconfig`,回车。这将列出所有网络接口的IP信息,包括IPv4和IPv6地址。 3. 查找与你的...
3. **网络信息**:获取网络状态,如IP地址、MAC地址、网络接口状态等,可以使用`socket`库(Python)、`ifconfig`命令(Linux)或`ipconfig`命令(Windows)。Python中还可以利用`psutil`库的网络接口来获取网络信息...