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

Getting IP address


7 replies to this topic

netwebindia

netwebindia
  • Full Members
  • 4 posts

Posted 26 June 2008 - 05:12

I want to get the IP address of the system on which I am deploying my installer.

felltier-a

felltier-a
  • Awaiting Authorisation
  • 85 posts

Posted 26 June 2008 - 12:43

Hi,

you could use vbs to get the adress:

Example:

strComputer = "."
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

Set IPConfigSet = objWMIService.ExecQuery ("Select * from Win32_NetworkAdapterConfiguration Where IPEnabled=TRUE")

For Each IPConfig in IPConfigSet
If Not IsNull(IPConfig.IPAddress) Then
For i=LBound(IPConfig.IPAddress) to UBound(IPConfig.IPAddress)
WScript.Echo IPConfig.IPAddress(i)
Next
End If
Next



regards,
Udo

netwebindia

netwebindia
  • Full Members
  • 4 posts

Posted 27 June 2008 - 05:22

Is there any inbuilt function in InstallShield for the IP address...??

nrlaing

nrlaing
  • Full Members
  • 14 posts

Posted 19 September 2008 - 20:48

This one took me a while to figure out. I ended up using a batch file to write to a text file, then I extracted the IP from that. Here's the batch file, pass a file name as the parameter of where to write the IP address to.

@echo off
set FILE=%1
if {%1}=={} set FILE=NOFILE
for /f "delims=[] tokens=2" %%i in ('ping -n 1 %COMPUTERNAME% ^| findstr /I "%COMPUTERNAME%"') do set IP=%%i
echo %IP%
if not %FILE%==NOFILE echo %IP% > %FILE%

Hope that helps,

Stefan Krueger

Stefan Krueger

    InstallSite.org

  • Administrators
  • 13,269 posts

Posted 25 September 2008 - 16:07

If the machine has multiple network connedctions (like wired LAN and wi-fi) wouldn't it also have multiple IP addresses?

nrlaing

nrlaing
  • Full Members
  • 14 posts

Posted 25 September 2008 - 18:48

QUOTE (Stefan Krueger @ 2008-09-25 11:07)
If the machine has multiple network connedctions (like wired LAN and wi-fi) wouldn't it also have multiple IP addresses?

Sure, but there has to be a default IP address. I'm not sure how Windows decides which is the default, but if you "ping" your computername, it will return with an IP address in the results. This is how I derived the IP, do you know of another way? I couldn't find a place in the registry that consistantly stored the IP across all Windows platforms.

Glytzhkof

Glytzhkof
  • Moderators
  • 1,447 posts

Posted 26 September 2008 - 14:06

I wrote a C++ class for this a while back. Essentially you can do a reverse DNS lookup (nslookup.exe by command line - or winsock gethostbyname() in code) to see what IP DNS has registered for the machine. You can then use WMI to iterate over all IP addresses on the system (there can be many - on a laptop you might have a nic, a modem and a wireless interface - that's 3 IP's right there). You should be able to find a match between one of the local IPs and the one registered in DNS - that's the one I'd use.
Regards
-Stein Åsmul

phood

phood
  • Full Members
  • 37 posts

Posted 01 October 2008 - 21:05

Here are two additional suggestions:

The ipconfig output could be parsed to get the IP Address.

Also, for DHCP IP addresses, you can often find the IP address cached in HKEY_LOCAL_MACHINE\Services. You can enumerate the subkeys for each service looking for \Parameters\Tcpip to find an entry for DhcpIPAddress. Unfortunately, InstallScript lacks a command to enumerate subkeys.

Good luck.

Pat