How to get IP ADDRESS or Computer name for client ?

VA Smalltalk is a "100% VisualAge compatible" IDE that includes the original VisualAge technology and the popular VA Assist and WidgetKit add-ons.

Moderators: Eric Clayberg, wembley, tc, Diane Engles, solveig

How to get IP ADDRESS or Computer name for client ?

Postby YSHAMSELDIN » Mon Feb 18, 2008 12:57 am

we have client server application generated by ibm visualage smalltalk 5.5


How can we know the computer name or ip address for client ( in run time )

thank you
YSHAMSELDIN
 
Posts: 2
Joined: Mon Feb 18, 2008 12:45 am

Re: How to get IP ADDRESS or Computer name for client ?

Postby Ralf » Mon Feb 18, 2008 1:26 am

I know only a solution under windows to get the computername

isWin32

| str |

str := System osType.
^str = 'WIN32s' or: [str = 'WIN32_NT' or: [str = 'WIN32_WINDOWS']]

getComputerName
"only under win."

| computerName ptr |

#needsWork.
self isWin32 ifFalse:[^''].

computerName := String new: 256.
ptr := (Smalltalk at: #OSPtr) new: 4.
ptr int32At: 0 put: computerName size.
((Smalltalk at: #OSCall) new) getComputerName: computerName lpcchBuffer: ptr.
^computerName abrTrimNullsFromEnd
Ralf
 
Posts: 41
Joined: Thu Nov 16, 2006 4:18 am

Re: How to get IP ADDRESS or Computer name for client ?

Postby Hans-Martin » Mon Feb 18, 2008 6:28 am

You can use
Code: Select all
hostName := SciSocketManager default getHostName.
hostAddress := SciSocketManager default getHostByName: hostName

to get the name and address of the current host.
Note that for multi-homed hosts, the hostAddress object may contain more than one IP address, it's up to your application to decide which one you want to use. And of couse, you should understand the socket communication interface classes to make sense of all this...

Cheers,
Hans-Martin
Hans-Martin
 
Posts: 12
Joined: Tue Oct 17, 2006 3:44 am

Re: How to get IP ADDRESS or Computer name for client ?

Postby marten » Mon Feb 18, 2008 7:05 am

I'm not sure, what you want - therefore two answers:

a) To retrieve the local client name (the name of computer the local
running program is located on):

Code: Select all
                          SciSocketManager default getHostName


b) To get the remote client name of a socket connection you should access to the instance of SciSocket:

Code: Select all

| sciSocket sciSocketAddress aSciHostEnt remoteHostname |

  sciSocketAddress  := sciSocket getPeerName.
  aSciHostEnt := SciSocketManager default getHostBySockName: sciSocketAddress.
  remoteHostname := aSciHostEnt name

Marten Feldtmann, Principal Smalltalk User, Private
SkypeMe callto://marten.feldtmann
marten
[|]
 
Posts: 641
Joined: Sat Oct 14, 2006 7:10 am
Location: Hamburg - Germany

Re: How to get IP ADDRESS or Computer name for client ?

Postby marten » Mon Feb 18, 2008 7:47 am

Hans-Martin wrote:Note that for multi-homed hosts, the hostAddress object may contain more than one IP address, it's up to your application to decide which one you want to use.


This is a good point. With Vista you might have at least two ip addresses with your local host and you get the IPv6 address as the default one (at least under my machine). Then you have to look at the result of

hostAddress := SciSocketManager default getHostByName: hostName

and hostAddress (instance of SciHostEnt) has the attribute named "addrType", which returns 2 (for IPV4) or 23 for (IPV6). For other interfaces you might ask hostAddress for "addrList", which returns a collection of integers - holding the IP numbers.

The following .NET code returns the first IPV4 address of a specific hostEntry and it shows, that .NET also returns a typed collection holding IPAddress
instances of the other interfaces (where under Smalltalk you have to convert it manually to further look at that list - this would be good way for
improvement !).

Code: Select all
        public static IPAddress MainIPv4Address(IPHostEntry hostEntry)
        {
            foreach (IPAddress eachAddress in hostEntry.AddressList)
            {
                if (eachAddress.AddressFamily == AddressFamily.InterNetwork)
                    return (eachAddress);
            }

            return null;
        }


I think, that here is code missing in Smalltalk to have a nicer behaviour ?
Marten Feldtmann, Principal Smalltalk User, Private
SkypeMe callto://marten.feldtmann
marten
[|]
 
Posts: 641
Joined: Sat Oct 14, 2006 7:10 am
Location: Hamburg - Germany

Re: How to get IP ADDRESS or Computer name for client ?

Postby Bob Nemec » Thu Feb 21, 2008 8:22 am

FWIW: we use a low tech approach to include the user and computer name in exception emails that get mailed to our help desk from our VA clients...

id := 'USERNAME' abtScanEnv.
computer := 'COMPUTERNAME' abtScanEnv.
Bob Nemec
Northwater Capital
Bob Nemec
[|]
 
Posts: 16
Joined: Mon Oct 16, 2006 5:07 am

Re: How to get IP ADDRESS or Computer name for client ?

Postby YSHAMSELDIN » Mon Feb 25, 2008 3:52 am

Thank you very much for all
i tray this code

id := 'USERNAME' abtScanEnv.
computer := 'COMPUTERNAME' abtScanEnv.
is ok
and


| computerName ptr |
computerName := String new: 20.
ptr := (Smalltalk at: #OSPtr) new: 4.
ptr int32At: 0 put: computerName size.
((Smalltalk at: #OSCall) new) getComputerName: computerName lpcchBuffer: ptr.
^computerName
is ok too
thank you again
YSHAMSELDIN
 
Posts: 2
Joined: Mon Feb 18, 2008 12:45 am

Re: How to get IP ADDRESS or Computer name for client ?

Postby veni » Thu Jan 06, 2011 2:16 am

I get my IP address details , through this site http://www.ip-details.com/ip-search/
It provides the best results for the details about to Search and find ip address's,domain name host's who is information including city, country, global latitude & longitude coordinates and also give internet speed accurately...........
veni
 
Posts: 1
Joined: Thu Jan 06, 2011 2:14 am

Re: How to get IP ADDRESS or Computer name for client ?

Postby antibuity » Tue Mar 22, 2011 10:28 pm

How can I find my port number, my internal ip address and my external ip address? I am trying out this app on my ipod that is like a remote for my computer. I want to see if it really works, so could anyone tell me how to find my port number, my internal ip address and my external ip address?
________________________
yahoo keyword tool ~ overture ~ traffic estimator ~ adwords traffic estimator
antibuity
 
Posts: 1
Joined: Fri Mar 18, 2011 1:09 am


Return to VA Smalltalk 7.0, 7.5 & 8.0

Who is online

Users browsing this forum: Yahoo [Bot] and 1 guest