Skip to main content
WolfShade
Brainiac
May 29, 2020
Question

Getting the client hostname when on an internal air-gapped network

  • May 29, 2020
  • 4 replies
  • 2240 views

Hello, all,

 

I know that there is a way to get, sometimes, the hostname of the client system connecting to an app/site.

 

 

<cfset inet = createObject("java","java.inet.InetAddress") />
<cfset session.remote_host= inet.getByName(cgi.remote_addr).getHostName() />

 

 

However, if you are in an air-gapped development network that does not have internet access, is there a way to do the same?

 

V/r,

 

^ _ ^

This topic has been closed for replies.

4 replies

EddieLotter
Inspiring
May 29, 2020

I'm not a JAVA programmer, but I'm guessing, from that method's name, that it is expecting a host name, not an IP address as the parameter.

Perhaps you meant to use the getHostName() method?

EddieLotter
Inspiring
May 29, 2020

P.S. I see you have getHostName() at the end, but I still think the problem is with using getByName().

Try: inet.getHostName(cgi.remote_addr)

WolfShade
WolfShadeAuthor
Brainiac
May 29, 2020

Sorry, guys.. should have phrased the question differently.

 

I'm not asking if it's possible to get the hostname of a system outside of the air-gapped network.  Can I get the hostname of a client system on the air-gapped network, internally.

 

Yes, we have our own DNS.

 

The sample code that I provided does not work on our air-gapped system; in fact, whenever those lines of code are run, it halts processing until it times out.

 

So I would like to be able to report the hostname of whichever dev client is accessing the pages via browser, like when a developer is testing changes to code on our development network.

 

V/r,

 

^ _ ^

BKBK
Community Expert
May 30, 2020

Oh, there was a typo: "java.inet.InetAddress" in place of "java.net.InetAddress".

An idea for a solution:

1) Find a way to create a collection containing every possible IP in the local network. For example, myDefault Gateway is 192.168.0.1. So I create a collection containing the 255x255 addresses from 192.168.0.0 to 192.168.254.254.

2) Run through the IPs in the collection, one by one, checking which ones return TRUE for the function

inetAddressObject.isReachable() 

 

You will find 2 fully worked out, ready-to-go, examples at https://www.quora.com/How-do-I-get-IP-Address-of-all-computers-in-a-network-using-java. The page also includes useful comments. 

 

In the first example, it might be useful to change the lines

 

System.out.println("Available: " + addr.getHostAddress()); // show that it is available
Available_Devices.add(addr.getHostAddress()); // if available, add it to final list

 

respectively to

 

System.out.println("Available: " + addr.getHostAddress() + ";" + addr.getHostName()); // show that it is available
Available_Devices.add(addr.getHostAddress() + ";" + addr.getHostName()); // if available, add it to final list

 

BKBK
Community Expert
May 30, 2020

The second example in the link I gave inspired the following solution in Windows:

 

 

<!--- Use DOS command 'arp -a' to fetch locally connected IPs --->
<cfexecute 
    name = "C:\Windows\system32\cmd.exe"  
    arguments="/c arp -a"  
    timeout="60" variable="connectedIPs"/>
  
 <!--- Use regular expression to identify the IPs --->
<cfset connectedIPArray=reMatch("\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b",connectedIPs)>

<!---<cfdump var="#connectedIPArray#" label="IPs connected to localhost">--->

<cfset inet = createObject("java","java.net.InetAddress") />

<!--- Store the host-name/IP pairs respectively as key/values in a struct --->
<cfif arrayLen(connectedIPArray) gt 0>
	<cfset session.remoteHostStruct=structNew()>
	<cfloop from="1" to="#arrayLen(connectedIPArray)#" index="i">
		<cfset structInsert(session.remoteHostStruct, "#inet.getByName(connectedIPArray[i]).getHostName()#", connectedIPArray[i]) >
	</cfloop>
	<cfdump var="#session.remoteHostStruct#" label="Hostnames/IPs connected to localhost">
</cfif>

 

BKBK
Community Expert
May 29, 2020

I agree with Dave.

Sounds like one of those trick questions. If your server is air-gapped, then it will have no internet connection to remote clients. Hence session.remote_host is null.

Community Expert
May 29, 2020

Probably not. Does your isolated development network have its own DNS services? (probably) Do those services reflect the accurate state of things on other networks? (probably not) Plenty of networks have internal DNS, but it typically only resolves the names of internal servers, not of external ones.

 

Dave Watts, Eidolon LLC

Dave Watts, Eidolon LLC