To use a regular expression to match an IP address, write ^ 192.168. [0-255] +. [0-255] $, but it is incorrect! [] [0-9a-z] But not [0-255] Regular Expressions
Use a regular expression to match the IP address.^192\.168\.[0-255]+\.[0-255]$But it is wrong!Regular Expression[]Not Restricted[0-9a-z]But not limited[0-255]?
containing the network number is not able to appear on any network.
Second, 10.*.*.*,172.16.*.*――172.31.*.*,192.168.*.*
The above three network segments are private addresses, can be used for their own networking, these addresses are mainly used in corporate internal networks, but not available on the Internet, Internet networks do not have these addresses, and computers using these three segments must go online through address translation (NAT), T
Code
Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->
Package
Test; ImportJava.net. inetaddress;ImportJava.net. networkinterface;ImportJava.net. socketexception;ImportJava.net. unknownhostexception;ImportJava. util. enumeration; PublicClassIPhone per { Public Static Void Main (string [] ARGs) Throws Unknownhostexception, socketexception { // Applicable only to Windows Inetaddress
Regular
Want to use a regular to match the IP address, so write ^192\.168\.[0-255]+\.[0-255]$ but is wrong!Is it [] not possible to limit it [0-9a-z] [0-255] ?
Reply content:
Regular
Want to use a regular to match the IP address, so write ^192\.168\.[0-255]+\.[0-255]$ but is wrong!Is it [] not possible to limit it
ImportOrg.slf4j.Logger;Importorg.slf4j.LoggerFactory;Importjava.net.InetAddress;ImportJava.net.NetworkInterface;Importjava.net.SocketException;Importjava.util.ArrayList;Importjava.util.Enumeration;Importjava.util.List; Public classIputil {Private Static FinalLogger Logger = Loggerfactory.getlogger (iputil.class); PrivateIputil () {}/*** This method describes: Get the IP
"Lnmp a key installation package" needs to obtain IP address, there are 2 kinds of cases: if the server only private network address does not have public network address , this time to obtain the IP (that is, private network
In php, there are user-defined functions that can help you determine the IP address, and we also use regular functions to determine the IP address. Below I will summarize some methods to verify the IP address. In php, there are us
host can be accessed from each other.2.2. Working principleUsing NAT mode, the virtual system uses the NAT (network address translation) function to access the public network through the network where the host machine resides. The TCP/IP configuration information for a virtual system in NAT mode is provided by the DHCP server of the VMNET8 (NAT) virtual network
The code is as follows:
Function GetIP (){If (! Empty ($ _ SERVER ["HTTP_CLIENT_IP"]) {$ Cip = $ _ SERVER ["HTTP_CLIENT_IP"];}Elseif (! Empty ($ _ SERVER ["HTTP_X_FORWARDED_FOR"]) {$ Cip = $ _ SERVER ["HTTP_X_FORWARDED_FOR"];}Elseif (! Empty ($ _ SERVER ["REMOTE_ADDR"]) {$ Cip = $ _ SERVER ["REMOTE_ADDR"];}Else {$ Cip = "cannot be obtained! ";}Return $ cip;}Echo GetIP ();?>
Here I have a public method to obtain
Public Static IPAddress Localip = dns.gethostaddresses (dns.gethostname ())2 . Where (ip = = IP. AddressFamily = = System.Net.Sockets.AddressFamily.InterNetwork)3 . First ();Dns.gethostaddresses (Dns.gethostname ()) to obtain an IP address of IPV4, IPV6, multip
"loopback" address, that is, only your own native visible, is the local address, more common has 127.0.0.1;1.2, 192.168.xxx.xxx belongs to private address (site), belonging to the local organization internal access, can only be visible on the local area network. The same 10.xxx.xxx.xxx, from 172.16.xxx.xxx to 172.31.xxx.xxx are private addresses, but also belong
/// ///provide the method of searching IP information from the pure IP database;/// Public classIpselect {FileStream ipfile; LongIP; Public stringIpfilepath; /// ///constructor Function/// ///Pure IP Database path PublicIpselect () {Ipfilepath="
of a remote host, you need to borrow the API function sendarp. this function uses the ARP Protocol to send ARP packets to the target host, and uses the returned IP and MAC address pairs stored in the cache to obtain the MAC address of the remote host.
Example:Int32 ldest = inet_addr (remoteip); // Destination IPInt32 lhost = inet_addr (localip); // local
. NET (C #) calls webService to obtain the region of the Client IP address (non-asynchronous ),Function Description:
This interface is used to obtain the region (country, city, etc.) of the IP address accessed by the client ). Enter an IP
intranet IP, in order to solve this problem, in the Apache agent before Jijiang x-forwarded-for prohibited, so still can through the httpservletrequest.getremotehost () to obtain the real IP client. Because Tomcat can not know is through the Apache proxy or Nginx agent, all, or through the way the above IP access. The Apache configuration is as follows: Request
PHP obtains the specific implementation of the city based on the IP address. File Directory: ipLocation ----- qqwry ---------- QQWry. Dat ----- ipCity. class. phpipCity. class. php file code: Copy the code as follows :? PhpclassipCity {*** obtain the file directory based on the IP address:
IpLocation----- Qqwry-------
the first valid.
Five. The problem I encountered here:
The company has written a good API, so I took it directly to use, x-forwarded-for what I did not control, he has.
But I can not get the x-forwarded-for header when I call (repeat with log, deploy, tired to say).
Then think, the client should have access to the server, now in the middle through the agent, usually our access to the server is not x-forwarded-for This parameter, then this parameter, it must be the agent to leave the client's
addresses into public IP addresses through address translation (NAT. Some bandwidth routers or other network devices usually use 192.168.1.1 as the default address. Because the private personal network is not interconnected with the external network, you can use random IP a
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.