On the internet to find a few Java to get the native IP address of the code, found that there are a few imperfect, their own tidy up a bit. All of a sudden want to get their own IP address to obtain, although the system comes with commands can be obtained, but I want to write a program to
One. Demand
Recently in a module, there is a background statistics function required According to the user's province to be counted.
So when the user is operating, the background should get their location information, and stored in the database.
Two. Analysis
As a mobile app, you want to target users
1. Can be obtained through the client system (Android,ios), (previously Android did use Baidu lbs positioning)
2. Can be H5 through the page, GPS positi
Java get the network IP, a shallow slightly ~1 Importjava.net.InetAddress;2 Importjava.net.UnknownHostException;3 4 /**5 * Get network IP6 * 1, get the local IP address7 * 2, get the server name of the machine8 * 3,
Analysis processThis comes from a number of projects that capture User IP and conduct user action records that are common and often used. General friends, you will see the following universal Get IP address method.
Copy Code code as follows:
function GetIP () {
if (Isset ($_server[' http_x_forwarded_for ')) {
$realip = $_server[' http_x_forwa
The premise is that the "Get real IP" feature is turned on in the SLB setting.
If only need to get real IP in the program, so long as in the program to get the value of http_x_forwarded_for is basically OK, do not need the following operation.
The following operations can
Recently Web get client IP, see the following article, reprinted, Shared (reprinted address: http://www.cnblogs.com/yejun/archive/2008/02/26/1082485.html)Usually we get the IP from the following code:string ip =System.Web.HttpContext.Current.Request.UserHostAddress; stri
There are many applications that require access to the IP address of the visitor, such as preventing unauthorized users or malicious users from accessing them. Java EE's servlet standard interface Javax.servlet.http.HttpServletRequest provides the GETREMOTEADDR () method for obtaining the visitor's IP address. REQUEST.GETREMOTEADDR () This approach is valid for most cases of
=context.request.servervariables["Http_x_forwarded_for"]. ToString (); Return Real Client IP.}else//not using proxy or can ' t get the Client IP{ip=context.request.servervariables["REMOTE_ADDR"]. ToString (); While it can ' t get the Client
In the past few days, I plan to build my favorite weather forecast system. Every time I browse the Web page, I can see the weather in different cities according to IP address changes. After two days of efforts and attempts, there was little progress. These mainly involve:
HtmlCodeAnalyze and obtain the Pinyin and location codes of all cities not provided by all websites.
IP address calculatio
In the JSP, the method to obtain the IP address of the client is: Request.getremoteaddr (), which is valid in most cases. However, the real IP address of the client cannot be obtained through the reverse proxy software such as Apache,nagix. If the reverse proxy software is used, the IP address obtained with the REQUEST.GETREMOTEADDR () method is: 127.0.0.1 or 192
Python has several methods to obtain the host's IP address, Python socket contains rich functions and methods to obtain the IP address information, socket object GetHostByName method can be based on the host name to obtain the local IP address, The GETHOSTBYNAME_EX method of the socket object can obtain a list of all IP
Three
String strhostname = System.Net.Dns.GetHostName ();
String clientipaddress = System.Net.Dns.GetHostAddresses (strhostname). GetValue (0). ToString ();
Method IV (ignoring the agent)
httpcontext.current.request.servervariables["Http_x_forwarded_for"];
Client:
Method Five
var ip = ' Alert ("Your IP address is" +IP);
Method VI (ignoring the agent)
Cop
Example 1
The code is as follows
Copy Code
Using System;Using System.Collections.Generic;Using System.Linq;Using System.Text;Using System.Net; Namespace Csharptest{Class Program{static void Main (string[] args){Console.Write (new program (). GetHostInfo ());Console.ReadLine ();}Get information such as local IPDProtected string GetHostInfo (){StringBuilder hostinfo = new StringBuilder ("");ipaddress[] Iphost = dns.gethostad
The easiest way to do it
The code is as follows
Copy Code
$ip = $_server["REMOTE_ADDR"];Echo $ip;
Most practical access to user IP address code
The code is as follows
Copy Code
function Get_real_ip () {$ip =false;if (!empty ($_server["HTTP_CLIENT_IP"]))
servers, this value is similar to the following: 203.98.182.163, 203.98.182.163, 203.129.72.215.Full use of Proxy server information replaces all of your information, as if you were using the proxy server directly to access the object.Get User IP$ip = ";foreach (Array (' http_client_ip ', ' http_x_forwarded_for ', ' http_from ', ' remote_addr ') as $v) {if (Isset ($_server[$v])) {if (! Preg_match ('/^\d{1,
PHP obtains the IP address and outputs the code of the array program. There are many ways to get IP addresses in php. next I will introduce how to use linux commands to get IP addresses and convert them into array output, the following describes some common methods to obtain
PHP Get visitors Real IP address in my time we need to get the user's real IP address, for example, log records, geo-location, user information, website data analysis, in fact, get the IP address is very simple $_server[' remote_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.