Recently, I made a low-level error in my project. I used obtaining the Client IP address as the IP address of the local machine. I was very trained. Ah, yes, I am so stupid, deserve it.
Java:
public String getIpAddr(HttpServletRequest request) { String ip = request.getHeader("x-forwarded-for"); if(ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { ip = request.getHeader("Proxy-Client-IP"); } if(ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { ip = request.getHeader("WL-Proxy-Client-IP"); } if(ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { ip = request.getRemoteAddr(); } return ip; }
Java obtains the IP address and Host Name of the local machine.
Import java.net. inetaddress; import java.net. unknownhostexception; import Java. util. properties; import Java. util. set; public class testsystemproperties {public static void main (string [] ARGs) {inetaddress netaddress = getinetaddress (); system. out. println ("Host IP:" + gethostip (netaddress); system. out. println ("Host Name:" + gethostname (netaddress); properties Properties = system. getproperties (); Set <string> set = properties. stringpropertynames (); // obtain information about the Java Virtual Machine and system. For (string name: Set) {system. out. println (name + ":" + properties. getproperty (name) ;}} public static inetaddress getinetaddress () {try {return inetaddress. getlocalhost ();} catch (unknownhostexception e) {system. out. println ("unknown host! ");} Return NULL;} public static string gethostip (inetaddress netaddress) {If (null = netaddress) {return NULL;} string IP = netaddress. gethostaddress (); // get the IP address return IP;} public static string gethostname (inetaddress netaddress) {If (null = netaddress) {return NULL;} string name = netaddress. gethostname (); // get the host address return name ;}}