We are looking for a way to find the MAC address of a client in Coldfusion.
Is there a way to do this? We are using CF 9 on JDK 1.6 which, I believe, allows us to use the Java network layer, but I would prefer to get be closer to the CFML layer.
We are looking for a way to find the MAC address of a client in Coldfusion.
Is there a way to do this? We are using CF 9 on JDK 1.6 which, I believe, allows us to use the Java network layer, but I would prefer to get be closer to the CFML layer.
You can't get the client's MAC address through java, as it's not passed in anywhere with the request. If you did want it, you would need some code that ran on the client's side. See here for more information: how to get a client's MAC address from HttpServlet?
You are able to get the server's MAC address using the below code as referenced in the answer above.
<cfset LocalHost = CreateObject( "java", "java.net.InetAddress" ).getLocalHost() />
<cfset Mac = CreateObject( "java", "java.net.NetworkInterface" ).getByInetAddress( LocalHost ).getHardWareAddress() />
<cfset MacAddress = '' />
<cfloop from="1" to="#ArrayLen( Mac )#" index="Pair">
<!--- Convert it to Hex, and only use the right two AFTER the conversion--->
<cfset NewPair = Right( FormatBaseN( Mac[ Pair ], 16 ), 2 ) />
<!--- If it's only one letter/string, pad it --->
<cfset NewPair = Len( NewPair ) EQ 1 ? '0' & NewPair : NewPair />
<!--- Append NewPair --->
<cfset MacAddress &= UCase( NewPair ) />
<!--- Add the dash --->
<cfif ArrayLen( Mac ) NEQ Pair>
<cfset MacAddress &= '-' />
</cfif>
</cfloop>
<cfdump var="#MacAddress#" />
I have not done this personally, but here's a link to a forum discussion were they explain how you can do this http://www.raymondcamden.com/forums/messages.cfm?threadid=39CC3269-19B9-E658-9DD1131DAB233CA8 otherwise this should work also http://tutorial17.learncf.com/