who command from non terminal in unix

I was executing a command "who -ms" from a CHUI application but i get below message,
It seems that who command can be executed only when we are logged directly in unix box as we have terminal.
Is there a way to get rid of this problem , or anyother command where i can get machine name of the terminal from where i am logged in?

process not attached to terminal                                               x
xUsage: who [-AabdHilmpqrsTtuwX?] [am {i,I}] [file]                            x
x         -A   Accounting entries                                              x
x         -a   All (AbdHlprTtu) options                                        x
x         -b   Boot time                                                       x
x         -d   Dead processes                                                  x
x         -H   Display a header (title)                                        x
x         -l   Login processes                                                 x
x         -m   Information about current terminal (same as 'am i'              x
x         -p   Processes other than getty or user process                      x
x         -q   Quick (only user and host name)                                 x
x         -r   Run level                                                       x
x         -s   Short form (suppress Activity and PID)                          x
x         -T,w Status of tty (+ writable, - not writable, x exclusive open, ? hx
x         -t   Time changes                                                    x
x         -u,i Activity and PID of shell                                       x
x         -X   Expanded user names

the hostname command perhaps?

hostname gives servername whereas I am looking for localhost
meaning for eg if i connect from any terminal to unix server , I would like to get the machine name which is used to connect and not the unix server name

What connection method are you using to connect to this computer. How are you running unix commands?
What Operating System and version are you running and what Shell do you use?
If you are connecting to a database engine, what it it?

Ps. We assume that CHUI means Character-based User Interface. Some sort of Shell breakout from your application?

we are invoking application using shell script .

I got another way of getting the user details ie using finger which gets me details in the application , but the problem is it gets details about all the session of the user who is logged in and not only for the current one

beliow is the command which i used , I dont think who command works if i am not in console . Somehow if we can get below commadn to work for currnet session using tty and $logname and get <logname>@<machine name from where we are logged in> , it will solve the purpose.

finger -b -p $LOGNAME | grep from
 

any idea