| 订阅 | 在线投稿
分享
 
 
当前位置: 王朝网络 >> c/c++ >> ru he yong C++ bian cheng huo de mou tai ji qi de IP di zhi

ru he yong C++ bian cheng huo de mou tai ji qi de IP di zhi

2008-06-01 02:04:46 编辑來源:互联网 评论
 
 
 
本文为【如何用C++编程获得某台机器的IP地址】的拼音翻译版
  bian yi :Northtibet xia zai yuan dai ma (zip ya suo wen jian , 1K)
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  dui yu zhe ge gu lao de wen ti ,VC zhi shi ku de jing hua qu yi ji yi wang de zai xian duo zhi zhong dou you xiang jin bu yi de miao shu 。 ben wen ti gong de fang fa shi yi ge bi jiao wan zheng de jie jue fang an , bing fu you ju ti de shi xian xi jie 。 xi wang da jia dui zhe ge wen ti you che di de shu xi 。 qi shi , jia ru ni shu xi Windows de Sockets API, bing le jie yi xie di ceng de Winsock zhi shi 。 na me yao huo de mou tai ji qi de IP di zhi bing bu shi shen me nan shi 。 yi tai ji qi ke yi zhuang duo kuai wang ka , yin ci ta jiu ke neng you duo ge IP di zhi 。 mu qian hen duo fa shao you de PC ji dou zhuang you duo kuai wang ka 。 qi zhong yi kuai wang ka yu tiao zhi jie tiao qi (MODEM) huo zhe ADSL shi pei qi xiang lian , ling yi kuai yu jia li de ju yu wang (LAN) xiang lian 。 dui yu you kuan dai lian jie tiao jian de jia ting , zhe geng shi yi zhong dian xing de pei zhi 。 ren he shi qing , yi dan ni zhi dao le jie jue de fang fa , yi qie dou hui bian de ru ci jian dan 。 xia mian shi ben wen ti gong de yi ge jian dan de kong zhi tai cheng xu ( cheng xu ming wei getip1), qi gong neng jiu shi xian shi ben ji de IP di zhi 。 ru tu yi suo shi :
如何用C++编程获得某台机器的IP地址
tu yi getip1 de yun xing hua mian
  xia mian shi getip1 cheng xu de dai ma , hen jian dan : ////////////////////////////////////////////////////////////////
  // getip1.cpp
  //
  // ben cheng xu bao gao ben ji shang mei yi kuai wang ka de IP di zhi
  // ming ling xing bian yi ming ling wei :
  //
  // cl getip1.cpp wsock32.lib
  //
  // qing yi ding yao zai huan jing bian liang zhong zheng que zhi ding LIB ku de lu jing ; ke yi yun xing vcvars32.bat
  //
  #include <winsock.h>
  #include <wsipx.h>
  #include <wsnwlink.h>
  #include <stdio.h>
  int main()
  {
   ////////////////
   // chu shi hua Windows sockets API. yao qiu ban ben wei version 1.1
   //
   Word wVersionRequested = MAKEWORD(1, 1);
   WSADATA wsaData;
   if (WSAStartup(wVersionRequested, &wsaData)) {
   PRintf("WSAStartup failed %s\n", WSAGetLastError());
   return -1;
   }
   //////////////////
   // huo de zhu ji ming .
   //
   char hostname[256];
   int res = gethostname(hostname, sizeof(hostname));
   if (res != 0) {
   printf("Error: %u\n", WSAGetLastError());
   return -1;
   }
   printf("hostname=%s\n", hostname);
   ////////////////
   // gen ju zhu ji ming huo qu zhu ji xin xi .
   //
   hostent* pHostent = gethostbyname(hostname);
   if (pHostent==NULL) {
   printf("Error: %u\n", WSAGetLastError());
   return -1;
   }
   //////////////////
   // jie xi fan hui de hostent xin xi .
   //
   hostent& he = *pHostent;
   printf("name=%s\naliases=%s\naddrtype=%d\nlength=%d\n",
  
   he.h_name, he.h_aliases, he.h_addrtype, he.h_length);
   sockaddr_in sa;
   for (int nAdapter=0; he.h_addr_list[nAdapter]; nAdapter++) {
   memcpy ( &sa.sin_addr.s_addr, he.h_addr_list[nAdapter],he.h_length);
   // shu chu ji qi de IP di zhi .
   printf("Address: %s\n", inet_ntoa(sa.sin_addr)); // xian shi di zhi chuan
   }
   //////////////////
   // zhong zhi Windows sockets API
   //
   WSACleanup();
   return 0;
  }
  
如何用C++编程获得某台机器的IP地址
geng duo nei rong qing kan C/C++ ji shu zhuan ti IP di zhi zhi shi pu ji zhuan ti java bian cheng kai fa shou ce zhuan ti , huo
  yao shi yong Winsock, shou xian bi xu tiao yong WSAStartup, zui hou jie shu shi bu yao wang le tiao yong WSACleanup。 yao huo qu IP di zhi , shou xian bi xu de dao ji qi de zhu ji ming (host name), tiao yong gethostname jiu ke yi shi xian , you le zhu ji ming , jie xia lai tiao yong gethostbyname lai huo qu bao kuo IP di zhi zai nei de geng duo de zhu ji xin xi 。
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  gethostbyname fan hui yi ge zhi xiang hostent shu ju jie gou de zhi zhen , zhe ge jie gou zai <winsock.h> wen jian zhong shi zhe yang ding yi de : // lai zi winsock.h
  strUCt hostent {
  char FAR * h_name; /* zheng shi de zhu ji ming */
  char FAR * FAR * h_aliases; /* bie ming lie biao */
  short h_addrtype; /* zhu ji di zhi lei xing */
  short h_length; /* di zhi chang du */
  char FAR * FAR * h_addr_list; /* di zhi qing dan */
  }; zhe shi ge dian xing de di ceng APIs shi yong de shu ju jie gou , hen duo ren dou bu shi hen shu xi ta 。 shi ji shang ,hostent shi yi ge bian chang de shu ju jie gou ,h_name shi zhu ji ming , zai li zi cheng xu zhong de zhi wei "zxn.hangwire.sdb"。 mei you bie ming (h_aliases)。h_addrtype shi di zhi lei xing ( huo zhe ye jiao di zhi jia zu ), zai li zi cheng xu zhong de zhi wei 2(AF_INET = internet, qi ta nei rong shen jian winsock.h)。h_length shi mei yi ge di zhi de chang du , yi zi jie wei dan wei 。 yin wei IP di zhi de chang du shi 4 ge zi jie , suo yi zai li zi cheng xu zhong de zhi wei 4,h_addr_list shi di zhi shu zu de kai shi dian , ta men yi ge jie zhe yi ge cun fang , jie yi shi yi ge null。 mei yi ge x.y.z.w shu zi zhan yi ge zi jie 。 wei le jiang IP di zhi ge shi hua wei x.y.z.w de xing shi , bi xu jiang di zhi shu zu xian kao bei dao yi ge jiao sockaddr de shu ju jie gou zhong , ran hou tiao yong yi ge fei fan de han shu inet_ntoa。 tu er shi hostent jie gou zai nei cun zhong cun fang shi yi tu :
如何用C++编程获得某台机器的IP地址
tu er hostent jie gou zai nei cun zhong de cun fang shi yi tu xiang xin yi shang de jie shi zai fu yi yue du dai ma , ni yi hou bu zai hui dui hostent jie gou gan dao sheng shu 。
  
   zui hou , shun zhu bian cheng yu kuai !
如何用C++编程获得某台机器的IP地址
geng duo nei rong qing kan C/C++ ji shu zhuan ti IP di zhi zhi shi pu ji zhuan ti Java bian cheng kai fa shou ce zhuan ti , huo【原文】【汉音对照
 
 
 
 
 
 
 
 
 
日版宠物情人插曲《Winding Road》歌词

日版宠物情人2017的插曲,很带节奏感,日语的,女生唱的。 最后听见是在第8集的时候女主手割伤了,然后男主用嘴帮她吸了一下,插曲就出来了。 歌手:Def...

兄弟共妻,我成了他们夜里的美食

老钟家的两个儿子很特别,就是跟其他的人不太一样,魔一般的执着。兄弟俩都到了要结婚的年龄了,不管自家老爹怎么磨破嘴皮子,兄弟俩说不娶就不娶,老父母为兄弟两操碎了心...

如何磨出破洞牛仔裤?牛仔裤怎么剪破洞?

把牛仔裤磨出有线的破洞 1、具体工具就是磨脚石,下面垫一个硬物,然后用磨脚石一直磨一直磨,到把那块磨薄了,用手撕开就好了。出来的洞啊很自然的。需要猫须的话调几...

我就是扫描下图得到了敬业福和爱国福

先来看下敬业福和爱国福 今年春节,支付宝再次推出了“五福红包”活动,表示要“把欠大家的敬业福都还给大家”。 今天该活动正式启动,和去年一样,需要收集“五福”...

冰箱异味产生的原因和臭味去除的方法

有时候我们打开冰箱就会闻到一股异味,冰箱里的这种异味是因为一些物质发出的气味的混合体,闻起来让人恶心。 产生这些异味的主要原因有以下几点。 1、很多人有这种习...

 
 
   bian yi :Northtibet   xia zai yuan dai ma (zip ya suo wen jian , 1K)    dui yu zhe ge gu lao de wen ti ,VC zhi shi ku de jing hua qu yi ji yi wang de zai xian duo zhi zhong dou you xiang jin bu yi de miao shu 。 ben wen ti gong de fang fa shi yi ge bi jiao wan zheng de jie jue fang an , bing fu you ju ti de shi xian xi jie 。 xi wang da jia dui zhe ge wen ti you che di de shu xi 。 qi shi , jia ru ni shu xi Windows de Sockets API, bing le jie yi xie di ceng de Winsock zhi shi 。 na me yao huo de mou tai ji qi de IP di zhi bing bu shi shen me nan shi 。 yi tai ji qi ke yi zhuang duo kuai wang ka , yin ci ta jiu ke neng you duo ge IP di zhi 。 mu qian hen duo fa shao you de PC ji dou zhuang you duo kuai wang ka 。 qi zhong yi kuai wang ka yu tiao zhi jie tiao qi (MODEM) huo zhe ADSL shi pei qi xiang lian , ling yi kuai yu jia li de ju yu wang (LAN) xiang lian 。 dui yu you kuan dai lian jie tiao jian de jia ting , zhe geng shi yi zhong dian xing de pei zhi 。 ren he shi qing , yi dan ni zhi dao le jie jue de fang fa , yi qie dou hui bian de ru ci jian dan 。 xia mian shi ben wen ti gong de yi ge jian dan de kong zhi tai cheng xu ( cheng xu ming wei getip1), qi gong neng jiu shi xian shi ben ji de IP di zhi 。 ru tu yi suo shi : [url=http://www.wangchao.net.cn/bbs/pydetail_1785320.html][img]http://image.wangchao.net.cn/it/1323423899378.gif[/img][/url] tu yi getip1 de yun xing hua mian    xia mian shi getip1 cheng xu de dai ma , hen jian dan : //////////////////////////////////////////////////////////////// // getip1.cpp // // ben cheng xu bao gao ben ji shang mei yi kuai wang ka de IP di zhi // ming ling xing bian yi ming ling wei : // // cl getip1.cpp wsock32.lib // // qing yi ding yao zai huan jing bian liang zhong zheng que zhi ding LIB ku de lu jing ; ke yi yun xing vcvars32.bat // #include <winsock.h> #include <wsipx.h> #include <wsnwlink.h> #include <stdio.h> int main() { //////////////// // chu shi hua Windows sockets API. yao qiu ban ben wei version 1.1 // Word wVersionRequested = MAKEWORD(1, 1); WSADATA wsaData; if (WSAStartup(wVersionRequested, &wsaData)) { PRintf("WSAStartup failed %s\n", WSAGetLastError()); return -1; } ////////////////// // huo de zhu ji ming . // char hostname[256]; int res = gethostname(hostname, sizeof(hostname)); if (res != 0) { printf("Error: %u\n", WSAGetLastError()); return -1; } printf("hostname=%s\n", hostname); //////////////// // gen ju zhu ji ming huo qu zhu ji xin xi . // hostent* pHostent = gethostbyname(hostname); if (pHostent==NULL) { printf("Error: %u\n", WSAGetLastError()); return -1; } ////////////////// // jie xi fan hui de hostent xin xi . // hostent& he = *pHostent; printf("name=%s\naliases=%s\naddrtype=%d\nlength=%d\n", he.h_name, he.h_aliases, he.h_addrtype, he.h_length); sockaddr_in sa; for (int nAdapter=0; he.h_addr_list[nAdapter]; nAdapter++) { memcpy ( &sa.sin_addr.s_addr, he.h_addr_list[nAdapter],he.h_length); // shu chu ji qi de IP di zhi . printf("Address: %s\n", inet_ntoa(sa.sin_addr)); // xian shi di zhi chuan } ////////////////// // zhong zhi Windows sockets API // WSACleanup(); return 0; } [url=http://www.wangchao.net.cn/bbs/pydetail_1785320.html][img]http://image.wangchao.net.cn/it/1323423899426.gif[/img][/url] geng duo nei rong qing kan C/C++ ji shu zhuan ti IP di zhi zhi shi pu ji zhuan ti java bian cheng kai fa shou ce zhuan ti , huo    yao shi yong Winsock, shou xian bi xu tiao yong WSAStartup, zui hou jie shu shi bu yao wang le tiao yong WSACleanup。 yao huo qu IP di zhi , shou xian bi xu de dao ji qi de zhu ji ming (host name), tiao yong gethostname jiu ke yi shi xian , you le zhu ji ming , jie xia lai tiao yong gethostbyname lai huo qu bao kuo IP di zhi zai nei de geng duo de zhu ji xin xi 。 gethostbyname fan hui yi ge zhi xiang hostent shu ju jie gou de zhi zhen , zhe ge jie gou zai <winsock.h> wen jian zhong shi zhe yang ding yi de : // lai zi winsock.h strUCt hostent { char FAR * h_name; /* zheng shi de zhu ji ming */ char FAR * FAR * h_aliases; /* bie ming lie biao */ short h_addrtype; /* zhu ji di zhi lei xing */ short h_length; /* di zhi chang du */ char FAR * FAR * h_addr_list; /* di zhi qing dan */ };   zhe shi ge dian xing de di ceng APIs shi yong de shu ju jie gou , hen duo ren dou bu shi hen shu xi ta 。 shi ji shang ,hostent shi yi ge bian chang de shu ju jie gou ,h_name shi zhu ji ming , zai li zi cheng xu zhong de zhi wei "zxn.hangwire.sdb"。 mei you bie ming (h_aliases)。h_addrtype shi di zhi lei xing ( huo zhe ye jiao di zhi jia zu ), zai li zi cheng xu zhong de zhi wei 2(AF_INET = internet, qi ta nei rong shen jian winsock.h)。h_length shi mei yi ge di zhi de chang du , yi zi jie wei dan wei 。 yin wei IP di zhi de chang du shi 4 ge zi jie , suo yi zai li zi cheng xu zhong de zhi wei 4,h_addr_list shi di zhi shu zu de kai shi dian , ta men yi ge jie zhe yi ge cun fang , jie yi shi yi ge null。 mei yi ge x.y.z.w shu zi zhan yi ge zi jie 。 wei le jiang IP di zhi ge shi hua wei x.y.z.w de xing shi , bi xu jiang di zhi shu zu xian kao bei dao yi ge jiao sockaddr de shu ju jie gou zhong , ran hou tiao yong yi ge fei fan de han shu inet_ntoa。 tu er shi hostent jie gou zai nei cun zhong cun fang shi yi tu : [url=http://www.wangchao.net.cn/bbs/pydetail_1785320.html][img]http://image.wangchao.net.cn/it/1323423899453.gif[/img][/url] tu er hostent jie gou zai nei cun zhong de cun fang shi yi tu    xiang xin yi shang de jie shi zai fu yi yue du dai ma , ni yi hou bu zai hui dui hostent jie gou gan dao sheng shu 。    zui hou , shun zhu bian cheng yu kuai ! [url=http://www.wangchao.net.cn/bbs/pydetail_1785320.html][img]http://image.wangchao.net.cn/it/1323423899500.gif[/img][/url] geng duo nei rong qing kan C/C++ ji shu zhuan ti IP di zhi zhi shi pu ji zhuan ti Java bian cheng kai fa shou ce zhuan ti , huo
󰈣󰈤
  免责声明:本文仅代表作者个人观点,与王朝网络无关。王朝网络登载此文出于传递更多信息之目的,并不意味着赞同其观点或证实其描述,其原创性以及文中陈述文字和内容未经本站证实,对本文以及其中全部或者部分内容、文字的真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
 
时尚秀气模特裴裴(8)
时尚秀气模特裴裴(7)
时尚秀气模特裴裴(6)
时尚秀气模特裴裴(5)
白墙黑瓦
广州东郊[原创]
八美至丹巴的东谷天然盆景
不一样的
 
>>返回首页<<
 
 
 为你推荐
 
 
 
 转载本文
 UBB代码 HTML代码
复制到剪贴板...
 
 热帖排行
 
 
 
 
 
©2005- 王朝网络 版权所有