Subject: RE: Validating a user’s location?
Not sure where I got this from cuz it doesn’t look like my coding format so I cannot take the credit for it but this code will retrieve the worstation IP:
Sub Click(Source As Button)
' create a scripting object, find out the environ, then
'either run winipcfg Or ipconfig
’ put result in a text file, read it, delete it
On Error Goto eh
Dim ws As Variant
Dim fso As Variant
Dim tmpFile As String
Dim thisLine As String
Dim ip As String
Set ws = CreateObject("WScript.Shell")
Set fso = CreateObject("Scripting.FileSystemObject")
Dim folderStr As String
TmpFile = "C:\Temp\ip.txt"
If ws.Environment("SYSTEM")("OS") = "" Then
’ attempt to establish whether win9x or nt based o/s
ws.run "winipcfg /batch " & TmpFile, 0, True
Else
ws.run "%comspec% /c ipconfig > " & TmpFile, 0, True
End If
Dim fileNum As Integer
fileNum = Freefile()
Open TmpFile For Input As fileNum
Do While Not Eof(fileNum)
Line Input #fileNum, ThisLine
If Instr(ThisLine, "Address") <> 0 Then
IP = Mid(ThisLine, Instr(ThisLine, ":") + 2)
Exit Do
End If
Loop
tmp$ = Inputbox$("", "IP Address ...", Cstr(IP))
Close fileNum
Kill TmpFile
'WinXP (NT? 2K?) leaves a carriage return at the end of line
If IP <> "" Then
If Asc(Right(IP, 1)) = 13 Then IP = Left(IP, Len(IP) - 1)
End If
Get_IP = IP
eh:
’ if there was a problem here it’s best to bail out completely
End
End Sub