Today, I've found how to get IP address of IPv6. Because we're using IPv6 address in our office and normally so far to use for IPv4 in Window7. That's why I gotta retrieve address of IPv6. On the other hand, CGI variable can retrieve IPv4 address of client machine.

How to get IPv6 is as follow. First of all, we need to create Java object first which called "java.net.InetAddress". Then, write as follow.

view plain print about
1<cfset gethost = createObject("java", "java.net.InetAddress")>
2<cfoutput>#gethost.getLocalHost()#</cfoutput>
3
4<!--- Output will be as follow --->
5PPSHEIN-PC/192.168.3.11

Honestly, it's combined with computer name/IP address. What I want is IP address only. That's why I need to remove computer name. There is two way to get IP address in above result.

  • Using List function
  • Using built-in function

Using list function

view plain print about
1<cfset returnIP = gethost.getLocalHost()>
2<cfoutput>#ListLast(returnIP, "/")#</cfoutput>

Using built-in function

view plain print about
1<cfoutput>#gethost.localhost.getHostAddress()#</cfoutput>