In TCP/IP, three IP address regions are reserved as private addresses. The address ranges are as follows:
10.0.0.0/8:10. 0.0.0 ~ 10.20.255.255
172.16.0.0/12: 172.16.0.0 ~ 172.31.255.255
192.168.0.0/16: 192.168.0.0 ~ 192.168.255.255 the network with the reserved address can only communicate internally, but cannot communicate with other networks. If you want to communicate with the outside, you must communicate with the outside through the gateway. Nat is used here, And the napt technology is used to ensure the communication proxy mechanism. In addition, although some broadband carriers use non-private addresses for user use, other users on the Internet cannot access these IP addresses due to route settings. The above two IP addresses can be referred to as Intranet IP addresses. The following IP addresses are not included in this discussion. If the IP address of the network interface on your machine falls within the reserved IP address range, you can be sure that you are in Intranet mode. Nat requires that the entire service connection is actively initiated from the Intranet to the Internet, and the Internet users cannot directly (actively) Initiate connection requests to the Intranet Service, unless) the Gateway provides port ing for service ports. Nat requires that the gateway at least has a public IP address, you can access the external server with an explicit IP address such as: http://ipid.shat.net/get the external IP address, compare this IP address with the IP address of the network interface on your machine to see if your IP address is an intranet IP address. You can use either of the following methods to determine the IP type: 1) Use ipconfig in the windos command station program. For example, the following Intranet IP address is 192.168.0.1 and the Internet IP address is 125.34.47.25. Therefore, it is a gateway. C:/Documents and Settings/user> ipconfig windows IP configurationethernet adapter local connection: Connection-specific DNS suffix.: IP address ............: 192.168.0.1 subnet mask ...........: 255.255.255.0 Default Gateway .........: 192.168.0.1 Ethernet Adapter {6c8aec26-0ec3-40fe-812e-a46778eca752}: Media State ...........: Media disconnected PPP adapter broadband Dialing: con Nection-specific DNS suffix.: IP address ............: 125.34.47.25 subnet mask ...........: 255.255.255 Default Gateway .........: 125.34.47.25 2) tracert is used to determine the IP type. If each hops is not an intranet IP address, it is an Internet IP address. Otherwise, if it is an intranet IP address, then, each hops displays the Intranet IP address of the Gateway. The following example clearly shows that it is an Internet IP address. C:/Documents and Settings/user> tracert www.baidu.com Tracing Route to www.a.shifen.com [202.108.22.5] over a maximum of 30 hops: 1 15 MS 16 MS 14 MS 125.34.40.1 2 14 MS * 61.148.8.9 3 26 MS 72 MS 40 MS xd-22-5-a8.bta.net.cn [202.108.22.5] Trace complete. 3) obtain the list of all IP addresses on the local machine by programming and analyze the IP address list: 1) if the list contains only lan ip addresses, the list is on the Intranet. 2) if the list contains lan ip addresses and public IP addresses, it indicates a gateway. 3) if the list contains only public IP addresses, it indicates an independent IP address. // Other platforms are not considered here. In the inet architecture test, the input IP address is host byte order // 0xa -- "10.0.0.0"> 24; 0xc0a8 -- "192.168.0.0. "> 16; 0x2b0 --" 127.17.0.1 "> 22int isinnerip (uint32_t a_ip) {int bvalid =-1; if (a_ip> 24 = 0xa) | (a_ip> 16 = 0xc0a8) | (a_ip> 22 = 0x2b0) {bvalid = 0;} return bvalid;} int isinnerip (char * a_strip) {return 0 ;}
IP-related applications// Obtain the list of all IP addresses on the local machine, and display int gethostip () // return int {struct sockaddr_in localaddr, destaddr; struct hostent * H in string and integer form respectively; char temp [128]; int nrect = gethostname (temp, 128); printf ("ipaddr src3 is: % s/n", temp); If (nrect! = 0) {printf ("error");} H = gethostbyname (temp); If (h) {for (INT nadapter = 0; H-> h_addr_list [nadapter]; nadapter ++) {memcpy (& destaddr. sin_addr.s_addr, H-> h_addr_list [nadapter], H-> h_length); // output the IP address of the machine. printf ("address string: % s/n", inet_ntoa (destaddr. sin_addr); // display the address string printf ("address INT: % d/N", destaddr. sin_addr.s_addr); // convert to an integer} return 0;} // check whether the string IP address is valid int ischecktrue (char * strip ){ Int value; For (INT I = 0; I <strlen (strip); I ++) {// Let's check if all entered char in entered // ip address are digits if (strip [I] = '. ') continue; If (isdigit (strip [I]) = 0) {return-1 ;}} return 0 ;} // convert the string IP address to an integer ipint str2intip (char * strip) // return int IP {int intip; If (! (Intip = inet_addr (strip) {perror ("inet_addr failed./N"); Return-1 ;}return intip ;}