Function IPReturn(outputtype As Integer)
Dim wsh As Object
Dim RegEx As Object, RegM As Object
Dim FSO As Object, fil As Object
Dim ts As Object, txtAll As String, TempFil As String
Dim target As String
Set wsh = CreateObject("WScript.Shell")
Set FSO = CreateObject("Scripting.FileSystemObject")
Set RegEx = CreateObject("vbscript.regexp")
TempFil = "C:\myip2.txt"
' Save ipconfig info to temporary file
wsh.Run "%comspec% /c ipconfig >" & TempFil, 1, True
'this can be run manually %comspec% /c ipconfig > C:\MY1.TXT
Set fil = FSO.GetFile(TempFil)
' Access temporary file
Set ts = fil.OpenAsTextStream(ForReading)
If outputtype = 1 Then target = "IP Address"
If outputtype = 2 Then target = "Subnet Mask"
If outputtype = 3 Then target = "Default Gateway"
txtAll = Trim(ts.ReadLine)
Do Until Left(txtAll, Len(target)) = target Or ts.atendofstream
txtAll = Trim(ts.ReadLine)
Loop
If ts.atendofstream = True And Left(txtAll, Len(target)) <> target Then ts.Close: Exit Function
ts.Close
With RegEx
.Pattern = "(\d{1,3}\.){3}\d{1,3}"
.Global = False
End With
Set RegM = RegEx.Execute(txtAll)
IPReturn = RegM(0)
Kill TempFil
Set ts = Nothing
Set wsh = Nothing
Set fil = Nothing
Set FSO = Nothing
Set RegM = Nothing
Set RegEx = Nothing
End Function