• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

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

LEGEND ,
May 29, 2020 May 29, 2020

Copy link to clipboard

Copied

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,

 

^ _ ^

TOPICS
Advanced techniques , Asynchronous , Builder , cfchart , Cffiddle , Connector , Database access , Documentation , Event gateways , Flash integration , Getting started , Monitoring , Reporting , Security , Server administration

Views

1.7K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 29, 2020 May 29, 2020

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 29, 2020 May 29, 2020

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
May 29, 2020 May 29, 2020

Copy link to clipboard

Copied

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,

 

^ _ ^

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 30, 2020 May 30, 2020

Copy link to clipboard

Copied

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

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 30, 2020 May 30, 2020

Copy link to clipboard

Copied

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>

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jun 01, 2020 Jun 01, 2020

Copy link to clipboard

Copied

Unfortunately, I cannot try this as CFEXECUTE is disabled on dev, staging, and production servers.

 

V/r,

 

^ _ ^

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 01, 2020 Jun 01, 2020

Copy link to clipboard

Copied

Ah, OK. Needs must. 🙂

 

So, let's try and run the DOS command in Java.

 

<cfscript>
	 output="";
    try {
    	runtime=createObject("java","java.lang.Runtime");
    	// Execute arp DOS command
        dosProcess=runtime.getRuntime().exec("cmd /c arp -a");

        dosProcess.waitFor(); 
        
        inputStream=createObject("java","java.io.InputStreamReader").init(dosProcess.getInputStream());
        bufferedReader=createObject("java","java.io.BufferedReader").init(inputStream);
        
        while(true) { 
          output&=bufferedReader.readLine();
          if(isNull(bufferedReader.readLine())) {
          	break;
          }   
        } 
        //writedump(output);
    } catch (any e) {
       writeDump(e);
    } 
</cfscript>

 <!--- Use regular expression to identify the IPs --->
<cfset connectedIPArray=reMatch("\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b",output)>

<!---<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>

 

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 01, 2020 Jun 01, 2020

Copy link to clipboard

Copied

Just discovered something peculiar: the cfexecute code returns more IPs than the Java code.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jun 01, 2020 Jun 01, 2020

Copy link to clipboard

Copied

LATEST

Another great idea that I can't use.  LOL!  US DoD doesn't give us access to cmd.exe, and our dev environment is set to match (mostly) staging and production environments, to minimize chances of code being written that works in dev but not staging or production.  Network security is pretty tight, around here.  No cmd.exe, no PowerShell, etc.  And when FACCSMs do access cmd.exe or PowerShell, even then their access is limited and logged.

 

V/r,

 

^ _ ^

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jun 01, 2020 Jun 01, 2020

Copy link to clipboard

Copied

Thank you for this idea, BKBK.  I'll look at those links and give it a shot.  I'll report my findings.

 

V/r,

 

^ _ ^

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 30, 2020 May 30, 2020

Copy link to clipboard

Copied

Are you sure your CF server is using a valid internal DNS server? Can that server be queried successfully using nslookup on the CF server? If so, you should be able to look up other hosts on the same network. It's very possible that those hosts don't actually have DNS names that are valid even on the internal network only.

 

Dave Watts, Eidolon LLC

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
May 29, 2020 May 29, 2020

Copy link to clipboard

Copied

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?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
May 29, 2020 May 29, 2020

Copy link to clipboard

Copied

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)

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation