This week's book giveaway is in the Python forum.
We're giving away four copies of Python Continuous Integration and Delivery and have Moritz Lenz on-line!
See this thread for details.
Win a copy of Python Continuous Integration and Delivery this week in the Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Devaka Cooray
  • Junilu Lacar
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Ron McLeod
  • Tim Holloway
  • Claude Moore
  • Stephan van Hulst
Bartenders:
  • Winston Gutkowski
  • Carey Brown
  • Frits Walraven

Getting Host Name of Client Computer  RSS feed

 
Ranch Hand
Posts: 1930
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a need to know the client computer host name.

This is a web application ran on an iSeries(as400) computer. The clients will be accessing the application using Windows.

Everything I have tried so far will yield the IP address of the client but not the host name.

My code(will not even return IP Address):



Console:
Error I/O exception: null
 
Sheriff
Posts: 13147
218
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A search on how to get client host name in Java yields a lot of discussion that leads me to believe that your attempts to do that is going to be unreliable at best. Also, I doubt many people here know what that WhoIsClient class does. Is that something you wrote yourself? I've never heard of a class like that before.
 
Saloon Keeper
Posts: 1110
36
IBM DB2 Java Netbeans IDE Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Steve,
as Junilu wrote, the first thing you should do is to clarify where WhoIsClient comes from, even if I strongly believe  that's part of Apache Commons library.
Indeed, at this web site (Apache Commons Net API page) I found practically the very same code you posted.
Moreover, the piece of code you posted is meant to run on the iSeries machine or on the remote client ? should try to connect to a DNS server in order to resolve names.
Is iSeries your DNS server ?

 
Sheriff
Posts: 21634
101
Chrome Eclipse IDE Java Spring Ubuntu VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
WhoisClient indirectly extends SocketClient which has methods getLocalAddress and getRemoteAddress. Both return an InetAddress which has some methods to get some more information. Most of these rely on your own DNS server.
 
Steve Dyke
Ranch Hand
Posts: 1930
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Junilu Lacar wrote:A search on how to get client host name in Java yields a lot of discussion that leads me to believe that your attempts to do that is going to be unreliable at best. Also, I doubt many people here know what that WhoIsClient class does. Is that something you wrote yourself? I've never heard of a class like that before.



This is a commons.net class
 
Junilu Lacar
Sheriff
Posts: 13147
218
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks, Claude, for the clarification.

@Steve: Given the code you wrote, I think you might have misunderstood what WhoisClient is for. In particular, on line 4 of that code, I don't think whoisClient.getLocalAddress() represents what you think it represents and that whole construct doesn't actually make sense, which is probably why you're getting an I/O exception with a null.

See WHOIS protocol for more information about what this WhoisClient class does.
 
Claude Moore
Saloon Keeper
Posts: 1110
36
IBM DB2 Java Netbeans IDE Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Claude Moore wrote:
should try to connect to a DNS server in order to resolve names.
Is iSeries your DNS server ?



I think that what I wrote is wrong, not sure that a DNS server offers by default whois protocol access.
 
Claude Moore
Saloon Keeper
Posts: 1110
36
IBM DB2 Java Netbeans IDE Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Junilu Lacar wrote:
@Steve: Given the code you wrote, I think you might have misunderstood what WhoisClient is for. In particular, on line 4 of that code, I don't think whoisClient.getLocalAddress() represents what you think it represents and that whole construct doesn't actually make sense.
See WHOIS protocol for more information about what this WhoisClient class does.



Right Junilu, it doesn't make sense. It should connect to a WhoIS server, which by default seems to be http://www.internic.net.
At this point I'm afraid that with WhoIs you can lookup names from public IPs registered on some Registrar authorities, not a single PC in your private lan. But I may be wrong...

 
Junilu Lacar
Sheriff
Posts: 13147
218
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The argument to whoisClient.connect() should be the address of the WHOIS service that you'll be querying. That's why it doesn't make sense to pass in whoisClient.getLocalAddress() to it as an argument.
 
Steve Dyke
Ranch Hand
Posts: 1930
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Junilu Lacar wrote:The argument to whoisClient.connect() should be the address of the WHOIS service that you'll be querying. That's why it doesn't make sense to pass in whoisClient.getLocalAddress() to it as an argument.



Thanks for all the clarification.

What I need to the hostname of the client. I there a way to do that?
 
Steve Dyke
Ranch Hand
Posts: 1930
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Junilu Lacar wrote:The argument to whoisClient.connect() should be the address of the WHOIS service that you'll be querying. That's why it doesn't make sense to pass in whoisClient.getLocalAddress() to it as an argument.



This just gives me the IP Address twice:



Console:
Step1
127.0.0.1
127.0.0.1
 
Claude Moore
Saloon Keeper
Posts: 1110
36
IBM DB2 Java Netbeans IDE Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Steve Dyke wrote:

This just gives me the IP Address twice:




Where does this piece of code come from ? It seems that you're dealing with an HttpRequest now...
 
Steve Dyke
Ranch Hand
Posts: 1930
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Claude Moore wrote:

Where does this piece of code come from ? It seems that you're dealing with an HttpRequest now...



Yes it the initial Servlet accessed by the web application when client initializes the application.
 
Saloon Keeper
Posts: 20498
115
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A computer doesn't have just one hostname. Most have at least 2: localhost and whatever name was given as the primary host name when the machine was configured for networking.

I have hosts with 6 or 7 names, for example, one shows up at blog,mousetech.com, www.mousetech.com, www5.mousetech.com, ns1.mousetech.com, and (indirectly) mail.mousetech.com. Among others and not counting virtual hosts within the physical host.

And let's talk about that indirection. I have machines that use NAT, IP forwarding, and other contrivances. All of my backend machines would resolve using reverse DNS as www.mousetech.com, even though they are actually many different machines 2 LAN layers away from the outside-facing www box itself.

In short, you cannot reliably determine the identity of a client from either an alleged hostname or IP address. You can do some firewalling, but that's about it, and even that can be bypassed in many instances.

The only reasonably certain way for a client to uniquely identify itself to a server is if the client and server sessions mutually agree on an identity over a secured chaannel, as, for example, the HttpSession on a JEE server. And even here, please note that the jsessionID is a key to the actual HttpSession, and that key can be changed without notice by the server. The jsessionid cannot be safely assumed to identify the client (HttpSession) all by itself.
 
Steve Dyke
Ranch Hand
Posts: 1930
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Tim Holloway wrote:A computer doesn't have just one hostname.



I did not realize it would be so complicated.

At one time the remoteHost call worked but we made some change to our network and now it is
no longer broadcast in the http request only the IP Address.

What I am trying to do is associate a computer(by name) to a label printer server software. Each label printer has an index#.

I have a data file with machine name and printer index so print jobs know where to go.

I need it in this fashion because multiple users use one machine and so I do not require a logon.

So right now to make this work, I use javascript and prompt the user to input computer name and store as cookie(if the cookie does not
already exist). The cookie expires every 365 days.
 
Tim Holloway
Saloon Keeper
Posts: 20498
115
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hmmmm.

I don't know how well this fits, but in the Unix/Linux/Mac world, there's a printing subsystem (developed by Apple) called CUPS. CUPS is somewhat like the corporate print manager (JES) that I used to use in my mainframe days. It operates using the IPP (Internet Printing Protocol) and it supports Windows clients. I don't know if there's a CUPS server for Windows, though.

Basically in this sort of model, the main difference between printing labels and printing, say, spreadsheets is that each printer has a unique CUPS identity. Or, if you prefer, compatible sets of printers can also be collected to form a print class. So printing labels is no different than printing any other document from an application, just a matter of selecting the appropriate printer target. A given target, however can also be fine-tuned so that the printer can demand that the proper pre-printed forms (or other custom paper) be loaded before printing is allowed to start and post-processors can be applied to do things like watermark the output. I've got a USB/wireless thermal printer I run like this for "notepad" outputs.

Of particular concern to you is that CUPS is (infuriatingly!) secure. It was designed to address massive security issues in the older Unix lpd printing system. And to make it easier (?) to administer, it does this by configuring much like an HTTP web server. The printers, classes, and control functions each have their own IPP URL and you can lock them down based on source IP address, network user ID and probably a few other options as well.

Windows Printing Services may provide something equally powerful these days, but Windows was originally designed as a personal user OS, not an enterprise OS, and whatever actions Microsoft have done to extend it have mostly passed me by since I dropped out of the Windows world about 10 years ago or so. But, as I said, at a minimum, Windows does have the ability to print as a CUPS client. regardless.

As far as multiple users sharing a resource anonymously, that's the kind of thing that makes auditors howl. Regardless of what kind of printing system you're using, print jobs should be uniquely trackable back to a user, not merely whoever happens to wander by an unsecured workstation.
 
Steve Dyke
Ranch Hand
Posts: 1930
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Tim Holloway wrote:Hmmmm.

As far as multiple users sharing a resource anonymously, that's the kind of thing that makes auditors howl. Regardless of what kind of printing system you're using, print jobs should be uniquely trackable back to a user, not merely whoever happens to wander by an unsecured workstation.



Thanks for the info but it may not help in my situation.
The label content is complied by my web application(this includes the printer id). Saved as .csv file. This file is the Ftp'd to a Loftware server watched folder which processes the print job to correct printer.

In our environment it is not feasible to assign 10+ users a computer to print ID labels or require these same 10+ users to log on to the printing application 50+ times a day.

They walk up to a kiosk already prompting them to san in a document# and the labels print out without any user interaction.
 
Tim Holloway
Saloon Keeper
Posts: 20498
115
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK, I just need to understand the players and the workflow better. Let's see what we can do.

You have a kiosk(s) with an attached document scanner, apparently. Is this kiosk available to the public, or just in-house? Also, since ordinarily a webapp cannot run a scanner, how do they communicate?

It's not that hard to generate barcodes directly from an application, so I'm assuming that the extra step involving Loftware does more than simply route stuff to a printer. And if there's a direct link from Loftware to the printing station(s), why can't the printer be secured as part of the Loftware connection? And do these printer(s) also print jobs from non-Loftware sources?

The final thing I need to determine is if these unsecured users are the same people who fed documents into the scanner or are they random employees who have to kick off a backend action for some reason.
 
Steve Dyke
Ranch Hand
Posts: 1930
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Tim Holloway wrote:OK, I just need to understand the players and the workflow better. Let's see what we can do.



The user has a document with a barcode on it. The barcode is scanned using a web application I developed. The application retrieves data from a remote data source.
It compiles the data including printer id into a csv file. This csv is ftp'd to a Loftware Server. This server contains the label template.
It uses the column values of the csv file to populate the template and then prints the label to the specified printer matching the id that was
sent in the csv file.
 
Tim Holloway
Saloon Keeper
Posts: 20498
115
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I still don't see how you're going from what sounds like a printed page into a webapp without some sort of additional help, but I suppose that's not important.

One thing you didn't mention though, was what role the hostname of the client computer plays in this process.
 
Steve Dyke
Ranch Hand
Posts: 1930
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Tim Holloway wrote:I still don't see how you're going from what sounds like a printed page into a webapp without some sort of additional help, but I suppose that's not important.

One thing you didn't mention though, was what role the hostname of the client computer plays in this process.



The printed page is a shop order or traveler with a barcode printed on it representing the Shop Order Number.
The web app is running on the Kiosk. The application has an input field that will take a handheld barcode scanner input/enter command.

When the application starts it looks at a remote data source to find out which Zebra Label printer(printer index) is assigned as the default to the computer running the application.
This is done by running an SQL statement with the machine name as a parameter.

Again, when the csv file created this printer index is included. The Loftware Server will use its printer table to out put to selected printer.

Currently the user is prompted to enter the machine name in manually.
 
Junilu Lacar
Sheriff
Posts: 13147
218
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Steve Dyke wrote:... Currently the user is prompted to enter the machine name in manually.


Seems like a cookie would be a simpler and more straightforward solution and it would eliminate the need for user intervention.
 
Tim Holloway
Saloon Keeper
Posts: 20498
115
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Lightbulb.

So you're using an HID scanner that runs the barcode in as keyboard input?

Here's one idea: Post bardcodes for the printers you want that kiosk to print to on the kiosk and let the user scan which one they want.

But if you want to have better control over knowing what kiosks can do what, you might look into client-side authentication.  There are at least 2 forms of this that come to mind.

1. Client-side SSL certs. These aren't good for really secure systems because if the computer gets stolen, so do the login credentials, but in your case, that's probably not a problem.

2. Windows Authentication. I believe that you said that all your kiosks were Windows machines. If they're all on a LAN or VLAN (not the open Internet), then they're almost certainly using domain logins. Thus, to even be able to run the browser, you'd have to login to the domain and therefore you'd have a domain userid. A suitable Realm plugin to a J2EE webapp server would be able to inject that identity into the webapp where you can get it simply by invoking getRemoteUser() on incoming HttpServletRequest objects. Actually, getRemoteUser() is also what you'd use for solution #1, since both solutions ultimately interface with the webapp server's authentication and authorization system.
 
Steve Dyke
Ranch Hand
Posts: 1930
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Junilu Lacar wrote:

Steve Dyke wrote:... Currently the user is prompted to enter the machine name in manually.


Seems like a cookie would be a simpler and more straightforward solution and it would eliminate the need for user intervention.



How do you propose to populate the cookie without user intervention?
 
Junilu Lacar
Sheriff
Posts: 13147
218
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm guessing the requirement to use the machine name instead of the IP address is to make it friendlier for humans. If that's the case and if a kiosk is supposed to print labels to a specific printer and that mapping is stored on the server, then again, I would think that a cookie is the simplest thing that could possibly work. From what has been said so far, it doesn't seem like the user needs to have the ability to override that setting.
 
Steve Dyke
Ranch Hand
Posts: 1930
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Junilu Lacar wrote:I'm guessing the requirement to use the machine name instead of the IP address is to make it friendlier for humans.



No, it is because our IP addresses are assigned dynamically where the machine name is static.

But still how will the cookie get assigned a value if it is not prompted for at some point?
 
Junilu Lacar
Sheriff
Posts: 13147
218
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Steve Dyke wrote:How do you propose to populate the cookie without user intervention?


Not quite sure I understand your question. Saving a cookie on a client doesn't need a user's intervention. Since you don't need the user's intervention, you can get the IP address of the kiosk computer from every request that gets submitted and instead of mapping printers to computer name, you can just map to the IP. Unless I'm totally missing the big picture and my guess that using the computer name was for the benefit of user-friendliness was off (apparently so), then all that can happen in the background, without the user even being aware of how it all happens.
 
Steve Dyke
Ranch Hand
Posts: 1930
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Tim Holloway wrote:Lightbulb.

2. Windows Authentication. I believe that you said that all your kiosks were Windows machines. If they're all on a LAN or VLAN (not the open Internet), then they're almost certainly using domain logins. Thus, to even be able to run the browser, you'd have to login to the domain and therefore you'd have a domain userid. A suitable Realm plugin to a J2EE webapp server would be able to inject that identity into the webapp where you can get it simply by invoking getRemoteUser() on incoming HttpServletRequest objects. Actually, getRemoteUser() is also what you'd use for solution #1, since both solutions ultimately interface with the webapp server's authentication and authorization system.



The following code always uses Step 1 condition. How do I get the  to work? getRemoteUser() returns null.

 
Tim Holloway
Saloon Keeper
Posts: 20498
115
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Junilu Lacar wrote:

Steve Dyke wrote:How do you propose to populate the cookie without user intervention?


Not quite sure I understand your question. Saving a cookie on a client doesn't need a user's intervention. Since you don't need the user's intervention, you can get the IP address of the kiosk computer from every request that gets submitted and instead of mapping printers to computer name, you can just map to the IP. Unless I'm totally missing the big picture and my guess that using the computer name was for the benefit of user-friendliness, then all that can happen in the background, without the user even being aware of how it all happens.



It gets messier when DHCP is involved.

Another thing that suggests itself is that since setting up a networked Windows machine does require giving the machine a name (which can be considered as its primary hostname), then having the client transmit that name would probably do.

Problem is, the sandbox around most webapp clients is probably not going to permit that. You'd probably need a custom ActiveX control or a similar horror. However, if you pull the data from the Windows domain userid, that's at least a little more straightforward. It does require manuall activating each client machine on initial setup, but the logic needed to support it is already pre-installed with Windows.
 
Tim Holloway
Saloon Keeper
Posts: 20498
115
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Steve Dyke wrote:
The following code always uses Step 1 condition. How do I get the  to work? getRemoteUser() returns null.



It requires 2 things. First, you have to enable it on each participating client machine. One of the rare cases where Windows secured a feature by default.

I think this is just a registry setting, but it has been a long time since I looked.

The other thing is that you have to hook up the webapp server's user authentication and authorization system to interface with Windows Domain security. If you're doing this on an i5 mainframe with WebSphere, I have really no clue on this - you'd have to check with IBM. For Tomcat, it's a special Realm module that gets configured in. Although if you run Tomcat on iSeries, I can't guarantee that there's a module on that platform, since the one that Tomcat would be using for Windows/Linux probably has Intel binary code in it. It's basically part of the same mechanism that supports single signon (SSO).

When done properly, getRemoteUser will return the Windows userid that the client machine was logged in under (and presumably automatically done at boot time for the kiosks). IF, that is, the machines are logged into the same Windows security domain. Non-Windows clients and Windows machines not on the local network have to use alternative methods.
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!