ip-address

Find number of active sessions created from a given client IP

假如想象 提交于 2019-12-17 10:42:56
问题 Is there a way to determine the number of active sessions created from a given client IP address? 回答1: The standard Servlet API doesn't offer facilities for that. Best what you can do is to maintain a Map<HttpSession, String> yourself (where the String is the IP address) with and check on every ServletRequest if the HttpSession#isNew() and add it to the Map along with ServletRequest#getRemoteAddr(). Then you can get the amount of IP addresses with an active session using Collections#frequency

Identifying country by IP address

时光怂恿深爱的人放手 提交于 2019-12-17 09:18:29
问题 Is there a way to figure out the country name just by looking at an IP address? I mean, do countries have specific ranges of IP addresses? For example, Australia can have IP addresses only in the range of 123.45.56.89 - 231.54.65.98 (just an example) 回答1: I think what you're looking for is an IP Geolocation database or service provider. There are many out there and some are free (get what you pay for). Although I haven't used this service before, it claims to be in real-time. https://kickfire

How can I convert IPV6 address to IPV4 address?

你离开我真会死。 提交于 2019-12-17 06:55:43
问题 I have application that uses IPv4 addresses (it stores them as long), so it only understands IPv4 addresses. Is it possible to convert IPv6 address to IPv4 with Java ? 回答1: While there are IPv6 equivalents for the IPv4 address range, you can't convert all IPv6 addresses to IPv4 - there are more IPv6 addresses than there are IPv4 addresses. The only sane way around this issue is to update your application to be able to understand and store IPv6 addresses. 回答2: The IPAddress Java library can

How can I convert IPV6 address to IPV4 address?

隐身守侯 提交于 2019-12-17 06:55:01
问题 I have application that uses IPv4 addresses (it stores them as long), so it only understands IPv4 addresses. Is it possible to convert IPv6 address to IPv4 with Java ? 回答1: While there are IPv6 equivalents for the IPv4 address range, you can't convert all IPv6 addresses to IPv4 - there are more IPv6 addresses than there are IPv4 addresses. The only sane way around this issue is to update your application to be able to understand and store IPv6 addresses. 回答2: The IPAddress Java library can

Most efficient way to store IP Address in MySQL [duplicate]

烈酒焚心 提交于 2019-12-17 06:25:38
问题 This question already has answers here : Datatype for storing ip address in SQL Server (10 answers) Closed 2 years ago . What is the most efficient way to store and retrieve IP addresses in MySQL? Right now I'm doing: SELECT * FROM logins WHERE ip = '1.2.3.4' Where ip is a VARCHAR(15) field. Is there a better way to do this? 回答1: For IPv4 addresses, you may want to store them as an int unsigned and use the INET_ATON() and INET_NTOA() functions to return the IP address from its numeric value,

Going from 127.0.0.1 to 2130706433, and back again

我只是一个虾纸丫 提交于 2019-12-17 06:09:37
问题 Using the standard Java libraries, what is the quickest way to get from the dotted string representation of an IPV4-address ( "127.0.0.1" ) to the equivalent integer representation ( 2130706433 ). And correspondingly, what is the quickest way to invert said operation - going from the integer 2130706433 to the string representation "127.0.0.1" ? 回答1: String to int: int pack(byte[] bytes) { int val = 0; for (int i = 0; i < bytes.length; i++) { val <<= 8; val |= bytes[i] & 0xff; } return val; }

Programmatically getting the gateway and subnet mask details

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-17 03:26:20
问题 How can I get gateway and subnet mask details in Android? 回答1: I have found a class called DhcpInfo within the android.net package. It has some public variables that stores the values of current Network parameters. But the problem is they return the value in integer converted from 8Bit shifted binary. Sample Image Describing thee Scenario: ****Here is a sample code:** **java file:**** package com.schogini.dhcp; import android.app.Activity; import android.content.Context; import android.os

Maximum length of the textual representation of an IPv6 address?

南笙酒味 提交于 2019-12-17 02:52:45
问题 I want to store the data returned by $_SERVER["REMOTE_ADDR"] in PHP into a DB field, pretty simple task, really. The problem is that I can't find any proper information about the maximum length of the textual representation of an IPv6 address, which is what a webserver provides through $_SERVER["REMOTE_ADDR"] . I'm not interested in converting the textual representation into the 128 bits the address is usually encoded in, I just want to know how many characters maximum are needed to store any

Fastest way to get IPv4 address from string

我怕爱的太早我们不能终老 提交于 2019-12-17 02:39:05
问题 I have the following code which is about 7 times faster than inet_addr . I was wondering if there is a way to improve this to make it even faster or if a faster alternative exists. This code requires that a valid null terminated IPv4 address is supplied with no whitespace, which in my case is always the way, so I optimized for that case. Usually you would have more error checking, but if there is a way to make the following even faster or a faster alternative exists I would really appreciate

Is it safe to trust $_SERVER['REMOTE_ADDR']?

只谈情不闲聊 提交于 2019-12-17 01:43:10
问题 Is it safe to trust $_SERVER['REMOTE_ADDR'] ? Can it be substituted by changing the header of request or something like that? Is it safe to write something like that? if ($_SERVER['REMOTE_ADDR'] == '222.222.222.222') { // my ip address $grant_all_admin_rights = true; } 回答1: Yes, it's safe. It is the source IP of the TCP connection and can't be substituted by changing an HTTP header. One case you may want to be worry of is if you are behind a reverse proxy in which case the REMOTE_ADDR will