Jump to content


This is a ready-only archive of the InstallSite Forum. You cannot post any new content here. / Dies ist ein Archiv des InstallSite Forums. Hier können keine neuen Beiträge veröffentlicht werden.
Photo

Finding Local Machine's IPAddress


7 replies to this topic

MSIYER

MSIYER
  • Full Members
  • 90 posts

Posted 12 July 2010 - 06:33

I need to get the IPAddress of my machine using any one of the following languages:
a)VBScript
b)JavaScript
c)C++
d)C#.

This IPAddress should be the same as the one other machines on the network use to discover my machine.

I have tried the gethostname method followed by gethostbyname .
This returns a list of IPAddresses on my system. I do not want to loop through the list and compare the list entries with my network IP pattern because:
Say I implement this logic of finding the IPAddress in my application and want to fetch the IPAddress of the User's machine(its sure that he/she will have a static IP), I will not know what pattern his/her IPAddress is in. So pattern comparison is out of question.

I have tried VBScript and the same result.

Please help me in solving this issue...



Stefan Krueger

Stefan Krueger

    InstallSite.org

  • Administrators
  • 13,269 posts

Posted 13 July 2010 - 13:03

There's a sample written in InstallScript at http://www.installsi.../en/isp_net.htm under "Retrieve Local TCP/IP Address". Maybe you can use this to build your own custom action.

Note that a computer may have mutliple IP addresses if it has multiple network adapters (LAN and WLAN for instance).

MSIYER

MSIYER
  • Full Members
  • 90 posts

Posted 15 July 2010 - 10:40

Thank you Stefan.
I had gone through that before I posted my query. Meanwhile, I got something from Windows Management Instrumentation(WMI) site.
I am using the following VBScript code to do the retrieval:

Function GetIPAddressLocalMachine()
Dim sHostname
sHostname = Session.Property( "HOSTANME" )
For Each oIP in GetObject("winmgmts:").ExecQuery _
("SELECT * FROM Win32_PingStatus WHERE address = '" & sHostname & "'")
sIP = oIP.ProtocolAddress
MsgBox sIP, , sHost
Next
MsgBox sIP, , sHost
Session.Property( "IPAddressLocalMachine" ) = sIP
End Function

I get the hostname of the machine from the registry and store it in a property named HOSTNAME.

It works in all the machines I tested. It gives me the network IP only.

Please update me if this has any drawbacks or any scenario where this may fail.

Thank you once more Stefan.

Thomas Hübner

Thomas Hübner
  • Full Members
  • 25 posts

Posted 22 November 2010 - 14:01

Is there a way to retrive all IP addresses in the target system? Maybe the compuster as more than one network adapters or has defined different IP addresses to one network adapter.

I want to provide a compobox with all defined IP addresses on a dialog during the setup. The selected address I will store in a config file like the http.conf file for apache.

Stefan Krueger

Stefan Krueger

    InstallSite.org

  • Administrators
  • 13,269 posts

Posted 22 November 2010 - 20:07

Similar to what ipconfig does? I guess there's a WMI interface for that but I don't know how to do it.

Glytzhkof

Glytzhkof
  • Moderators
  • 1,447 posts

Posted 23 November 2010 - 04:42

Maybe have a look here: http://www.pcreview....ead-1922838.php . I did something like this in a DLL custom action once. It was hell using WMI in C++, but I can probably dig out the class I created to get the list of IPs on the system if need be.
Regards
-Stein Åsmul

Thomas Hübner

Thomas Hübner
  • Full Members
  • 25 posts

Posted 23 November 2010 - 08:43

Thanks for the link. tongue.gif
It seems that it will work. In a Basic script I get all of my local IP addresses, included that from my virtual adapters (VirtualBox and loopback adapters).

Now I will try to convert the code in InstallScript to use it in my Installer.

Glytzhkof

Glytzhkof
  • Moderators
  • 1,447 posts

Posted 24 November 2010 - 04:03

I haven't tried to do this in Installscript, but it sure was hairy in C++. I am not hooked up with access to all my code right now, but do private message me if you run into big problems with this. I got the class somewhere, and though it may drag in some dependencies I remember it as pretty self contained.
Regards
-Stein Åsmul