Link to home
Start Free TrialLog in
Avatar of pnorris99
pnorris99Flag for Australia

asked on

VB2008 - DNS lookup from IP

Hi Guys,

I initially did this in VBS but then realised I can't run a VBS in the WinPE environment so need to make this an executable.

All of our machines IP's and Hostnames are prestaged based on their Mac address, so mac address 00:00:00:00:00:01 would be given IP 192.168.1.2 and Machine name Computer_1 by default in DNS.

What I need to do is create a small app using VB that will look for the machines name in DNS, this will then allow me to change the answer file on the fly inserting the Machine name in the answer file making sure that all of my machines are named correctly bsed on their DNS entry.

Any help would be really cool thanks guys.

Phil,
Avatar of pnorris99
pnorris99
Flag of Australia image

ASKER

Here is the VBS script I created and was going to use, but 2 problems 1 being no NSlookup in the PE env, and 2 you cant run VBS in the PE env.


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

Set colItems = objWMIService.ExecQuery _
    ("Select * From Win32_NetworkAdapterConfiguration Where IPEnabled = True")

For Each objitem In colitems
   strIPAddress = Join(objitem.IPAddress, ",")

   Exit For
Next

set objShell = createobject("wscript.shell")

strParams = "%comspec% /c NSlookup " & strIPAddress
Set objExecObj = objShell.exec(strParams)

Do While Not objExecObj.StdOut.AtEndOfStream
	strText = objExecObj.StdOut.Readline()
	If instr(strText, "Server") then 
		strServer = trim(replace(strText,"Server:",""))
	Elseif instr (strText, "Name") Then
		strhost = trim(replace(strText,"Name:",""))
	End if
Loop

NewString = Right(strhost,6)  

If instr(strhost,".TEST.COM.AU") Then

Artsstring = Replace(strhost, ".TEST.COM.AU", "")

Const ForReading = 1
Const ForWriting = 2

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("X:\sources\wdsunattend\wdsimageunattend.xml", ForReading)

strText = objFile.ReadAll
objFile.Close
strNewText = Replace(strText, "$REPLACE$", Artsstring)

Set objFile = objFSO.OpenTextFile("X:\sources\wdsunattend\wdsimageunattend.xml", ForWriting)
objFile.WriteLine strNewText
objFile.Close


End If

If instr(strhost,".TEST.COM.AU") Then

Albanystring = Replace(strhost, ".TEST.COM.AU", "")

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("X:\Sources\wdsunattend\WdsImageUnattend.xml", ForReading)

strText = objFile.ReadAll
objFile.Close
strNewText = Replace(strText, "$REPLACE$", Albanystring)

Set objFile = objFSO.OpenTextFile("X:\Sources\wdsunattend\WdsImageUnattend.xml", ForWriting)
objFile.WriteLine strNewText
objFile.Close

End If

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of kambleamar
kambleamar
Flag of Afghanistan image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thats perfect thanks for your time mate,

P.