Copier le lien dans le Presse-papiers
Copié
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,
^ _ ^
Copier le lien dans le Presse-papiers
Copié
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
Copier le lien dans le Presse-papiers
Copié
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.
Copier le lien dans le Presse-papiers
Copié
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,
^ _ ^
Copier le lien dans le Presse-papiers
Copié
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
Copier le lien dans le Presse-papiers
Copié
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>
Copier le lien dans le Presse-papiers
Copié
Unfortunately, I cannot try this as CFEXECUTE is disabled on dev, staging, and production servers.
V/r,
^ _ ^
Copier le lien dans le Presse-papiers
Copié
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>
Copier le lien dans le Presse-papiers
Copié
Just discovered something peculiar: the cfexecute code returns more IPs than the Java code.
Copier le lien dans le Presse-papiers
Copié
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,
^ _ ^
Copier le lien dans le Presse-papiers
Copié
Thank you for this idea, BKBK. I'll look at those links and give it a shot. I'll report my findings.
V/r,
^ _ ^
Copier le lien dans le Presse-papiers
Copié
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
Copier le lien dans le Presse-papiers
Copié
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?
Copier le lien dans le Presse-papiers
Copié
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)
Préparez-vous ! Une expérience Adobe Community améliorée arrive en janvier.
En savoir plus