Getting host name in Perspective

When using perspective, I have a need to inject the hostname of the system issuing commands. In Designer for Perspective shows the host name, which is what I need. When using the browser, this property contains an IP address. I also tried with Perspective Workstation and the property still contains an IP address. Is there any way to collect the hostname for the system performing the command within Persepctive?

Use at your own risk:

import socket
def getHostName(ipaddr,stripdomain = False):
	if validateIp(ipaddr):
		hostname = socket.gethostbyaddr(ipaddr)[0]
		#Verify that we actually got a host name
		if not validateIp(hostname):
			if stripdomain:
				return hostname[:hostname.find('.')]
				return hostname
			#If the hostname can't be found then this will just return the ip address
			return hostname
		#Just return the ipaddr because it's probably the host name
		return ipaddr

def validateIp(ipaddr):
		return True
	except socket.error:
		return False

We’ve got something similar where I will have to print reports to different printers based on the host name of the clients. We are assuming that those clients will be dynamic.

If you pass an ip address that can’t be resolved back to a host then you will get the IP address back.

This fails for any client behind a NAT, and for setups where the gateway’s DNS servers are isolated from your typical DHCP server for clients. The only reliable solution for Perspective would be some (future) support in Perspective Workstation.

I’ll give it a shot. In this instance it might work as it’s for inside a control center. If we had many external clients, it may cause an issue. Thanks for the input!

Yeah it’s not failsafe for sure. But for what I need it for it works.