VC++ 获取本地IP和计算机名
主要是两个函数的使用,gethostname();、gethostbyname();
自定义两个函数GetLocalHostName获取计算机名、GetIPAddress获取IP地址
int CIPDlg::GetLocalHostName(CString &strHostName)
{
char szHostName[];
int nRetCode;
nRetCode = gethostname(szHostName, sizeof(szHostName));
if(nRetCode != )
{
strHostName = _T("Not available");
return WSAGetLastError();
}
strHostName = szHostName;
return ;
}
int CIPDlg::GetIPAddress(const CString &strHostName, CString &strIPAddress)
{
struct hostent FAR *lpHostEnt = gethostbyname(strHostName);
if(lpHostEnt == NULL)
{
strIPAddress = _T("");
return WSAGetLastError();
}
LPSTR lpAddr = lpHostEnt->h_addr_list[];
if(lpAddr)
{
struct in_addr inAddr;
memmove(&inAddr, lpAddr, );
strIPAddress = inet_ntoa(inAddr);
if(strIPAddress.IsEmpty())
{
strIPAddress = _T("Not avilable");
}
}
return ;
}
VC++ 获取本地IP和计算机名的更多相关文章
- Android 获取本地外网IP、内网IP、计算机名等信息
一.获取本地外网IP public static String GetNetIp() { URL infoUrl = null; InputStream inStream = null; try { ...
- 获取本地IP地址的vc代码
作者:朱金灿 来源:http://blog.csdn.net/clever101 获取本地IP地址有两种做法.一种是使用gethostname函数,代码如下: bool CSocketComm::Ge ...
- Linux下编程获取本地IP地址的常见方法
转载于:http://blog.csdn.net/k346k346/article/details/48231933 在进行linux网络编程时,经常用到本机IP地址.本文罗列一下常见方法,以备不时之 ...
- Linux C 网络编程 - 获取本地 ip 地址,mac,通过域名获取对应的 ip
获取本地 ip 地址,mac,通过域名获取对应的 ip, 是网络编程可能遇到的比较常见的操作了,所以总结如下(封装了3个函数), 直接上代码: #include <stdio.h> #in ...
- LINUX - 获取本地ip
Linux编程获取本机IP地址的几种方法 参考: https://blog.csdn.net/zhongmushu/article/details/89944990 https://www.cnblo ...
- Linux编程获取本地IP
#include <stdio.h> #include <sys/types.h> #include <ifaddrs.h> #include <netine ...
- Java获取本地IP地址
import java.net.InetAddress; import java.net.UnknownHostException; public class IpTest { public stat ...
- 获取本地IP地址信息
2012-06-05 /// <summary> /// 获取本地IP地址信息 /// </summary> void G ...
- Android应用开发提高篇(1)-----获取本地IP
链接地址:http://www.cnblogs.com/lknlfy/archive/2012/02/21/2361802.html 一.概述 习惯了Linux下的网络编程,在还没用智能机之前就一直想 ...
随机推荐
- spring boot 环境搭建
1.开发工具 https://spring.io/tools/sts/all 2.demo https://start.spring.io 3.下载maven https://maven.apache ...
- js toSting方法实现
function toString (val: any): string { return val == null ? '' : typeof val === 'object' ? JSON.stri ...
- SQLite的升级(转)
做Android应用,不可避免的会与SQLite打交道.随着应用的不断升级,原有的数据库结构可能已经不再适应新的功能,这时候,就需要对SQLite数据库的结构进行升级了. SQLite提供了ALTER ...
- 【转】SQL2008的sa账户被禁用,其他账户无法连接的解决方法
或者你还有其它的sysadmin权限的账号,你可以用此账号登录,重置SA密码. 但是在以下情况下,怎么办呢? 1. SA密码丢失或者SA账号被禁用. 2. 你进行了一些安全操作,把BuiltinAdm ...
- loadrunner中log的使用初步总结
1.log的设置方式 . 在 runtime setting中可以设置log的生成方式: 默认的log方式: Enable logging选中,log option是Send messages onl ...
- js实现new Date(),时间对象和时间戳操作
1.js中实现时间date对象 var myDate = new Date();//获取系统当前时间,结果:Wed Aug 09 2017 00:00:00 GMT+0800 (中国标准时间) 2.获 ...
- 微信小程序:input输入框和form表单几种传值和取值方式
1.传值:index下标传值.页面navigator传值 1.index下标 实现方式是:data-index="{{index}}"挖坑及e.currentTarget.data ...
- Nginx日志分析利器之GoAccess
1.介绍GoAccess 是一个用来统计 Apache Web 服务器的访问日志的工具,可即时生成统计报表,速度非常快 查看的统计信息有: 统计概况,流量消耗等 访客排名 动态Web请求 静态web请 ...
- HDUOJ-----取(m堆)石子游戏
取(m堆)石子游戏 Time Limit : 3000/1000ms (Java/Other) Memory Limit : 32768/32768K (Java/Other) Total Sub ...
- CoreText实现图文混排之文字环绕及点击算法
系列文章: CoreText实现图文混排:http://www.jianshu.com/p/6db3289fb05d CoreText实现图文混排之点击事件:http://www.jianshu.co ...