黑基网 首页 学院 网络安全 查看内容

获取IP的C 代码

2009-11-9 09:57| 投稿: security

摘要: #include<stdio.h> #include<winsock2.h> #pragma comment(lib,"ws2_32.lib") void CheckIP(vo...
#include<stdio.h> #include<winsock2.h> #pragma comment(lib,"ws2_32.lib") void CheckIP(void) //定义CheckIP()函数,用于获取本机IP地址 { WSADATA wsaData; char name[255]; //定义用于存放获得的主机名的变量 char *ip; //定义IP地址变量 PHOSTENT hostinfo; //调用MAKEWORD()获得Winsock版本的正确值,用于加载Winsock库 if ( WSAStartup( MAKEWORD(2,0), &wsaData ) == 0 ) { //现在是加载Winsock库,如果WSAStartup()函数返回值为0,说明加载成功,程序可以继续 if( gethostname ( name, sizeof(name)) == 0) { //如果成功地将本地主机名存放入由name参数指定的缓冲区中 if((hostinfo = gethostbyname(name)) != NULL) { //这是获取主机名,如果获得主机名成功的话,将返回一个指针,指向hostinfo,hostinfo //为PHOSTENT型的变量,下面即将用到这个结构体 ip = inet_ntoa (*(struct in_addr *)*hostinfo->h_addr_list); //调用inet_ntoa()函数,将hostinfo结构变量中的h_addr_list转化为标准的点分表示的IP //地址(如192.168.0.1) printf("%s\n",ip);//输出IP地址 } } WSACleanup( ); //卸载Winsock库,并释放所有资源 } } int main(void) { CheckIP(); return 0; }
小编推荐:欲学习电脑技术、系统维护、网络管理、编程开发和安全攻防等高端IT技术,请 点击这里 注册黑基账号,公开课频道价值万元IT培训教程免费学,让您少走弯路、事半功倍,好工作升职加薪!



免责声明:本文由投稿者转载自互联网,版权归原作者所有,文中所述不代表本站观点,若有侵权或转载等不当之处请联系我们处理,让我们一起为维护良好的互联网秩序而努力!联系方式见网站首页右下角。


鲜花

握手

雷人

路过

鸡蛋

相关阅读

发表评论

最新评论

引用 游客 2018-1-6 18:20
<a href="http://www.lifecareplanners.org/merry_en/nike-blazer-white-blue">nike blazer white blue</a>,<a href="http://www.loughtonartscentre.org/merry_en/nike-air-huarache-gym-red">nike air huarache gym red</a>
[url=http://www.familyoffaithbiloxi.org/merry_en/nike-air-presto-flyknit-white-womens]nike air presto flyknit white womens[/url]
引用 游客 2018-1-5 03:58
<a href="http://www.showcasesoundandlights.com/">showcasesoundandlights</a>, <a href="http://www.strive2begreat.com/">strive2begreat</a>,
[url=http://www.marketingpartnering.com/]marketingpartnering[/url]
引用 游客 2018-1-4 06:10
<a href="http://www.tamrac-inc.com/">tamrac-inc</a>, <a href="http://www.lakegenevaziplines.com/">lakegenevaziplines</a>,
[url=http://www.valenciadjs.com/]valenciadjs[/url]
引用 游客 2018-1-4 05:36
<a href="http://www.natfam.net/">natfam</a>, <a href="http://www.beingamerican.net/">beingamerican</a>,
[url=http://www.mysewingtreasures.com/]mysewingtreasures[/url]
引用 游客 2018-1-4 02:31
<a href="http://www.usvsp.com/nike-lunarepic-low-flyknit-purple-black-merry_en">nike lunarepic low flyknit purple black</a>,<a href="http://www.ansims.com/reekbok-revenge-plus-vintage-white-red-merry_en">reekbok revenge plus vintage white red</a>
[url=http://www.chloemade.com/nike-air-force-1-easter-egg-edition-merry_en]nike air force 1 easter egg edition[/url]
引用 游客 2018-1-3 15:47
<a href="http://www.worldclasstesuqueviews.com/merry_en/nike-air-huarache-camo">nike air huarache camo</a>,<a href="http://www.thebarntopsham.com/merry_en/nike-internationalist-pink-red">nike internationalist pink red</a>
[url=http://www.theozprincipleblog.com/merry_en/nike-air-huarache-run-ultra-rosa]nike air huarache run ultra rosa[/url]
引用 游客 2018-1-3 03:53
<a href="http://www.chakwaini.net/nike-shox-black-mesh-merry_en">nike shox black mesh</a>,<a href="http://www.sweetdog.net/nike-blazer-low-vintage-suede-blue-merry_en">nike blazer low vintage suede blue</a>
nike zoom vomero silver orange http://www.officepedia.net/nike-zoom-vomero-silver-orange-merry_en
引用 游客 2018-1-2 19:07
<a href="http://www.vito-serwis.com/merry_en/womens-nike-internationalist-yellow-green">womens nike internationalist yellow green</a>,<a href="http://www.valley1051.com/merry_en/mens-nike-free-run-2-grey-white">mens nike free run 2 grey white</a>
[url=http://www.tomaszwolszczak.com/merry_en/nike-air-presto-ultra-br-for-sale]nike air presto ultra br for sale[/url]
引用 游客 2018-1-2 17:59
<a href="http://www.nassautraffic.com/">nassautraffic</a>, <a href="http://www.selidbetim95.com/">selidbetim95</a>,
[url=http://www.soundsteppers.com/]soundsteppers[/url]
引用 游客 2018-1-2 03:51
<a href="http://www.sangthi.com/">sangthi</a>, <a href="http://www.ptcsindia.com/">ptcsindia</a>,
[url=http://www.voyard-travaux.com/]voyard-travaux[/url]
引用 游客 2018-1-1 21:56
<a href="http://www.mohebin.net/womens-nike-air-max-95-zen-venti-black-boots-merry_en">womens nike air max 95 zen venti black boots</a>,<a href="http://www.chaumyerre.net/adidas-zx-900-merry_en">adidas zx 900</a>
nike free run 2 triple black http://www.mariedudu.net/nike-free-run-2-triple-black-merry_en
引用 游客 2018-1-1 21:36
<a href="http://www.petrakov.net/">petrakov</a>, <a href="http://www.faitesundon.net/">faitesundon</a>,
[url=http://www.lizaadams.com/]lizaadams[/url]
引用 游客 2018-1-1 08:50
<a href="http://www.totalwellnessmanagement.com/">totalwellnessmanagement</a>, <a href="http://www.yourwellbalanceddog.com/">yourwellbalanceddog</a>,
[url=http://www.websites-ecuador.com/]websites-ecuador[/url]
引用 游客 2018-1-1 01:09
<a href="http://www.robert-meredith.com/">robert-meredith</a>, <a href="http://www.newforestlandrovers.com/">newforestlandrovers</a>,
[url=http://www.**greenfaster.com/]**greenfaster[/url]
引用 游客 2017-12-31 17:18
<a href="http://www.vsgenerator.com/merry_en/stefan-janoski-max-blue">stefan janoski max blue</a>,<a href="http://www.tynesideautomatics.com/merry_en/nike-free-flyknit-5.0-womens-grey-red">nike free flyknit 5.0 womens grey red</a>
[url=http://www.westplanokarate.com/merry_en/zapatillas-nike-hyperdunk-2015]zapatillas nike hyperdunk 2015[/url]
引用 游客 2017-12-31 08:26
<a href="http://www.mymetronymommy.com/">mymetronymommy</a>, <a href="http://www.pelicanbiopharma.com/">pelicanbiopharma</a>,
[url=http://www.keepswingingbook.com/]keepswingingbook[/url]
引用 游客 2017-12-30 19:01
<a href="http://www.residencebijoudanslaforet.com/">residencebijoudanslaforet</a>, <a href="http://www.nationalinsurancexchange.com/">nationalinsurancexchange</a>,
[url=http://www.singularitythevideogame.com/]singularitythevideogame[/url]
引用 游客 2017-12-30 03:21
<a href="http://www.zabranjenopusenje.org/merry_en/nike-free-trainer-5.0-georgia">nike free trainer 5.0 georgia</a>,<a href="http://www.gentlemenventures.org/merry_en/nike-lebron-soldier-10-red-white">nike lebron soldier 10 red white</a>
[url=http://www.jhostettercounseling.com/merry_en/asics-gel-noosa-tri-7-womens-neon-pink-coral-shoes]asics gel noosa tri 7 womens neon pink coral shoes[/url]
引用 游客 2017-12-30 02:26
<a href="http://www.uksecuritycompany.com/merry_en/nike-sb-dunk-freddy-krueger-for-sale">nike sb dunk freddy krueger for sale</a>,<a href="http://www.xiaomimi4i.com/merry_en/womens-nike-free-5.0-wolf-grey">womens nike free 5.0 wolf grey</a>
[url=http://www.wecanrepairanycar.com/merry_en/nike-dunk-high-true-id]nike dunk high true id[/url]
引用 游客 2017-12-30 00:11
<a href="http://www.seamenco.com/">seamenco</a>, <a href="http://www.koahine.org/">koahine</a>,
[url=http://www.nashvillerealestateexpert.com/]nashvillerealestateexpert[/url]

查看全部评论(46)


新出炉

返回顶部