servlets - Java - How to detect IP version -


i'm getting client ip address via below method :

public static string getclientipaddr(httpservletrequest request) {       string ip = request.getheader("x-forwarded-for");       ...     return ip }  

now want detect if ipv4 or ipv6.

you create inetaddress , check if became ipv4 or ipv6 instance

inetaddress address = inetaddress.getbyname(ip); if (address instanceof inet6address) {     // it's ipv6 } else if (address instanceof inet4address) {     // it's ipv4 } 

it seems bit awkward, though, , hope there better solution.


Comments

Popular posts from this blog

image - ClassNotFoundException when add a prebuilt apk into system.img in android -

I need to import mysql 5.1 to 5.5? -

Java, Hibernate, MySQL - store UTC date-time -