public String getIpAddr(HttpServletRequest request){
String ipAddress = null;
ipAddress = request.getHeader("x-forwarded-for");
if(ipAddress == null || ipAddress.length() == 0 || "unknown".equalsIgnoreCase(ipAddress)) {
ipAddress = request.getHeader("Proxy-Client-IP");
}
if(ipAddress == null || ipAddress.length() == 0 || "unknown".equalsIgnoreCase(ipAddress)) {
ipAddress = request.getHeader("WL-Proxy-Client-IP");
}
if(ipAddress == null || ipAddress.length() == 0 || "unknown".equalsIgnoreCase(ipAddress)) {
ipAddress = request.getRemoteAddr();
if(ipAddress.equals("127.0.0.1")){
InetAddress inet=null;
try {
inet = InetAddress.getLocalHost();
} catch (UnknownHostException e) {
e.printStackTrace();
}
ipAddress= inet.getHostAddress();
}
}
//对于通过多个代理的情况,第一个IP为客户端真实IP,多个IP按照','分割
if(ipAddress!=null && ipAddress.length()>15){ //"***.***.***.***".length() = 15
if(ipAddress.indexOf(",")>0){
ipAddress = ipAddress.substring(0,ipAddress.indexOf(","));
}
}
return ipAddress;
}
分享到:
相关推荐
foreach (IPAddress _IPAddress in Dns.GetHostEntry(Dns.GetHostName()).AddressList) { if (_IPAddress.AddressFamily.ToString() == "InterNetwork") { AddressIP = _IPAddress.ToString(); ip = _IP...
dbip-api-client ... 有关API响应的更多详细...$ ipAddress = $ argv [ 1 ] or die ( "usage: {$argv[0]} <ip>\n" ); // lookup IP address information $ addrInfo = DBIP \ Address :: lookup ( $ ipAddress ); var_
2 I run the two py file code in two machines,first, you should get to know the ip address of server machine, and replace the HOST constant with your own server ip, then type message firstly on ...
function get_real_ipaddress() { if (!empty($_SERVER['HTTP_CLIENT_IP'])) { return $_SERVER['HTTP_CLIENT_IP']; } elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) { return $_SERVER['...
IPAddress ip = IPAddress.Any; ServerInfo = new IPEndPoint(ip, this.GetPort()); ServerSocket.Bind(ServerInfo);//将SOCKET接口和IP端口绑定 ServerSocket.Listen(10);//开始监听,并且挂起数为10 ...
"The DHCP client was unable to obtain an IP network address from a DHCP server. Do you want to see future DHCP messages?" This message means that TCP/IP has initialized but without any addressing ...
IPEndPoint iep = new IPEndPoint(IPAddress.Broadcast, port); byte[] sen = Class2.senDataToByte(sendDatas); udpclient.Send(sen, sen.Length, iep); } /// /// 获取本机IP /// public void IPselect...
[your vitural server]>system>services, enable smtp and pop3 services and set ipaddress binding with or without ssl/tls. the host name is required when set bindings. eg. bind smtp service to smtp.[your...
This programma achieves a simple FTP process. the client is able to get file or updata file from server. the ip address should be localhost
NetConf.gwip = *((u_long*)GET_GW_IP); NetConf.sn = *((u_long*)GET_SN_MASK); NetConf.dns = *((u_long*)GET_DNS_IP); PRINTLN("Get network information from DHCP Server..."); ...
有一个私有网络10.*.*.*,Client A是其中的一台计算机,这个网络的网关(一个NAT设备)的外网IP是155.99.25.11(应该还有一个内网的IP地址,比如10.0.0.10)。如果Client A中的某个进程(这个进程创建了一个UDP ...
* DHCP, AutoIP/APIPA (Zeroconf), ACD (Address Conflict Detection) and (stateless) DHCPv6 * UDP (User Datagram Protocol) including experimental UDP-lite extensions * TCP (Transmission Control ...
FTP_Listener = new TcpListener(System.Net.IPAddress.Parse(this.IPAddress),this.Port); } //D閙arrage de l'閏oute FTP_Listener.Start(); this.m_listening=true; while(true) { /...
The packet switch uses the destination IP address in the packet to determine the outgoing link. Asking which road to take is analogous to a packet asking which outgoing link it should be forwarded on...
udpClient.BeginSend(datagram, datagram.Length, Address, Port, SendCompleted, udpClient); } } } } private void SendCompleted(IAsyncResult ar) { UdpClient udp = ar.AsyncState as Udp...
echo "New client connected: { $ip } \n" ; // remove the listening socket from the clients-with-data array $key = array_search ( $sock , $read ); unset( $read [ $key ]); } // loop through all...
Part 1: Introduction and TCP/IP Chapter 1. Introduction Section 1.1. Introduction Section 1.2. A Simple Daytime Client Section 1.3. Protocol Independence Section 1.4. Error Handling: ...
System.Net.IPAddress clientIP = System.Net.IPAddress.Parse(Request.UserHostAddress);//根据目标IP地址获取IP对象 System.Net.IPHostEntry ihe = System.Net.Dns.GetHostEntry(clientIP);//
EndPoint remoteEP = (EndPoint)(new IPEndPoint(IPAddress.Any, 0)); byteData = new byte[1024]; //Receive data asynchornously. clientSocket.BeginReceiveFrom(byteData, 0, byteData.Length, Socket...