VC obtains the Host Name and Internet IP address (cstring type)

Source: Internet
Author: User

As mentioned in the previous chapter, you can dynamically obtain the Host Name and Internet IP address under VC. If you are interested, see it!

/*************************************** *******************************/<Br/> /* function Description: obtain the current Internet IP address <br/>/* parameter: None <br/>/* return value: Return Internet IP address, cstring type string <br/>/*: koma 2009.08.21 <br/> /******************************** **************************************** /<br/> cstring cqdlg:: getipaddress () <br/>{< br/> char Buf [max_path] ={ 0 }; <br/> char chtempip [128]; <br/> char chip [64]; <br/> cstring STRP Ath; <br/> strpath = getexepath () + "// netip. ini "; <br/> urldownloadtofile (0," http://www.ip138.com/ip2city.asp ", strpath, 0, null); </P> <p> file * fp = fopen (strpath, "R"); <br/> If (FP! = NULL) <br/>{< br/> fseek (FP, 0, seek_set); <br/> fread (BUF, 1,256, FP ); <br/> fclose (FP); <br/> char * iindex = strstr (BUF, "["); <br/> If (iindex) <br/>{< br/> sprintf (chtempip, "% s", iindex); <br/> int nbuflen = strlen (chtempip ); <br/> for (INT I = 0; I <nbuflen; I ++) <br/> {<br/> chip [I] = chtempip [I + 1]; </P> <p> If (chtempip [I] = ']') <br/> {<br/> chip [I-1] = '/0 '; <br/> deletefile (strpath); <br/> Continue; <br/>}< br/> cstring strtemp = ""; <br/> If (chip! = "") <Br/>{< br/> strtemp. format ("% s", Chip); <br/>}< br/> return strtemp; <br/>}</P> <p> /*************************** **************************************** * *****/<br/>/* function description: get the current host name <br/>/* parameter: None <br/>/* return value: Return host name, cstring type string <br/>/*: koma 2009.08.21 <br/> /******************************** **************************************** /<br/> cstring cqdlg:: gethostname () <br/>{< br/> word WV Ersionrequested; <br/> wsadata; <br/> int err; <br/> wversionrequested = makeword (2, 0); <br/> err = wsastartup (wversionrequested, & wsadata); <br/> If (Err! = 0) <br/>{< br/> return err; <br/>}< br/> If (lobyte (wsadata. wversion! = 2) | hibyte (wsadata. wversion )! = 0) <br/>{< br/> wsacleanup (); <br/> return (char) wsavernotsupported; <br/>}</P> <p> char szhostname [256]; <br/> int nretcode; <br/> cstring STR = ""; </P> <p> // call an API to obtain the host name <br/> nretcode = gethostname (szhostname, sizeof (szhostname); <br/> If (nretcode! = 0) <br/>{< br/> return wsagetlasterror (); <br/>}< br/> If (szhostname! = "") <Br/>{< br/> Str. format ("Host Name: % s", szhostname); <br/>}< br/> return STR; <br/>}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.