SYNACK Posted March 5, 2009 Posted March 5, 2009 Just a random idea but since you are playing in VBS and WMI anyway you could do it all in VBS if your webserver runs windows by using WinRM and WMI If you install WinRM on the server and client then you can run WMI querys over the net, the code from below allows you to raname files through WMI so you should be able to copy a premade html template with your location to be location.html depending on which school you were in. Rename or copy a file (VBScript) - Windows Server Cookbook A completely random solution but uses some pretty cool toys and allows you to stick to native VBS. The other options listed above are probably easier though.
SimpleSi Posted March 6, 2009 Author Posted March 6, 2009 Well I've gone for the simple ftp the ipaddress.txt file up to webserver and then check its contents on my main php index page and display cross ref my ip with the school. Current code is in 2 files - one vbs and one bat (you don't seem to be able to jsut ftp in vbs without extra components) strComputer = "." Dim result Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2") Set colItems = objWMIService.ExecQuery _ ("Select * From Win32_NetworkAdapterConfiguration Where IPEnabled = True") For Each objItem in colItems ' Wscript.Echo objItem.MACAddress For Each strAddress in objItem.IPAddress if left(strAddress,3) = "10." then ' Wscript.Echo strAddress result=WriteFileText("c:\ipaddress.txt",strAddress) end if Next Next Set WShell = CreateObject("WScript.Shell") 'WShell.Run WShell.ExpandEnvironmentStrings("%COMSPEC%") "/c c:\ftpipaddress.bat" WShell.Run("%COMSPEC% /K c:\ftpipaddress.bat"), 1, True Function WriteFileText(sFilePath, sText) Dim objFSO 'As FileSystemObject Dim objTextFile 'As Object Const ForReading = 1 Const ForWriting = 2 Const ForAppending = 8 Set objFSO = CreateObject("Scripting.FileSystemObject") Set objTextFile = objFSO.CreateTextFile(sFilePath, True) ' Write a line. objTextFile.Write (sText) objTextFile.Close End Function and @echo off echo user *********> ftpcmd.dat echo ********>> ftpcmd.dat echo bin>> ftpcmd.dat echo put c:\ipaddress.txt>> ftpcmd.dat echo quit>> ftpcmd.dat ftp -n -s:ftpcmd.dat www.*********.sch.uk del ftpcmd.dat exit @synack - as usual you suggestion is good but I don't have that sort of access to the server (and no idea if its windows or linux ) Ta for suggestions and if anyone has a more elegant all-in-one script (maybe a bat file that can parse the output of ipconfig to find a 10.* address - my dos bat coding not good enough for that ) regards Simon
SimpleSi Posted March 6, 2009 Author Posted March 6, 2009 PS just noticed the Critical alert from another school so I'm off regards Simon
mac_shinobi Posted March 6, 2009 Posted March 6, 2009 @echo off ipconfig | find "IP Address" > ip.txt type ip.txt pause
SimpleSi Posted March 6, 2009 Author Posted March 6, 2009 I like your thinking Yes - that would find the line with IP in it and I could parse the rest of it in PHP so it is a solution But I was looking for the DOS guru who can make tea using the cmd line and just extract the first 10.xxx.yyy.zzz address it finds active regards Simon
mac_shinobi Posted March 6, 2009 Posted March 6, 2009 if you used that vbscript into a html page because you have the strComputer ="." would that get the ip address of the computer it was ran on or what exactly ?
sahmeepee Posted March 6, 2009 Posted March 6, 2009 (edited) If you want a DOS version to pick out the first 10.x.yy.zzz line, how's this? save this as ip.bat then run it. THe commands won't run properly directly from the commandline because of a weirdness around %%s @echo off ipconfig | findstr "10.[0-9]" | findstr "Address" > ip.txt for /F "usebackq tokens=15* delims= " %%a in (ip.txt) do echo %%a del ip.txt Edited March 6, 2009 by sahmeepee it's important to be tidy ;) 1
mac_shinobi Posted March 6, 2009 Posted March 6, 2009 If you want a DOS version to pick out the first 10.x.yy.zzz line, how's this? save this as ip.bat then run it. THe commands won't run properly directly from the commandline because of a weirdness around %%s @echo off ipconfig | findstr "10.[0-9]" | findstr "Address" > ip.txt for /F "usebackq tokens=15* delims= " %%a in (ip.txt) do echo %%a del ip.txt I can't do all the whiz bang stuff in a bat file as per above lol - Im more used to vbs and more modern languages.
sahmeepee Posted March 6, 2009 Posted March 6, 2009 Obviously instead of just doing an echo it could do: wget http://yourhost.sch.uk/mapMe.php?ip=%%a No pootling about required!
SYNACK Posted March 7, 2009 Posted March 7, 2009 (edited) Not need to resort to DOS This way gets rid of one textfile all together and does it all (other than the actual FTPing) in VBS WriteLocationFile "c:\ipaddress.txt",GetLocalIP SendViaFTP DeleteLocationFile "c:\ipaddress.txt" Sub WriteLocationFile(sFilePath, sText) Dim objFSO 'As FileSystemObject Dim objTextFile 'As Object Set objFSO = CreateObject("Scripting.FileSystemObject") Set objTextFile = objFSO.CreateTextFile(sFilePath, True) objTextFile.Write (sText) ' Write a line. objTextFile.Close End Sub Sub SendViaFTP() Dim WSHShell Set WSHShell = WScript.CreateObject("WScript.Shell") WSHShell.Run "ftp", 1, false ' open normal window and do not wait Wscript.Sleep 200 'sleep for 0.2 of a second WSHShell.SendKeys "open www.*********.sch.uk" & VbCrLf Wscript.Sleep 1000 'sleep for 0.2 of a second WSHShell.SendKeys "User *********" & VbCrLf Wscript.Sleep 200 'sleep for 0.2 of a second WSHShell.SendKeys "********" & VbCrLf Wscript.Sleep 200 'sleep for 0.2 of a second WSHShell.SendKeys "bin" & VbCrLf Wscript.Sleep 200 'sleep for 0.2 of a second WSHShell.SendKeys "put c:\ipaddress.txt" & VbCrLf Wscript.Sleep 200 'sleep for 0.2 of a second WSHShell.SendKeys "quit" & VbCrLf Set WSHShell = Nothing End Sub Sub DeleteLocationFile(strFilePath) set objFSO = CreateObject("Scripting.FileSystemObject") objFSO.DeleteFile(strFilePath) End Sub Function GetLocalIP strComputer = "." Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2") Set colItems = objWMIService.ExecQuery("Select * From Win32_NetworkAdapterConfiguration Where IPEnabled = True") For Each objItem in colItems For Each strAddress in objItem.IPAddress if left(strAddress,3) = "10." then GetLocalIP = strAddress end if Next Next End Function Not sure about the " WSHShell.SendKeys "User *********" & VbCrLf" line as now that it is not connecting inline you may just need to provide the username without the prefix. The sleep intervals could also be cut down lots, i just left them long to see what was going on, I would leave a gap of 1.5 seconds for it to actually connect though depending on how quick your FTP server is. Edited March 7, 2009 by SYNACK 1
sahmeepee Posted March 7, 2009 Posted March 7, 2009 (edited) I can see how that is much more elegant (ahem!) So without resorting to 12 pages of VBscript ... @echo off REM Take down your particulars: set IPUpdaterHostname=www.yourschool.sch.uk set IPUpdaterUsername=yourFTPUsername set IPUpdaterPassword=yourFTPPassword(Leave blank to be prompted) REM Extracting the IP address: ipconfig | findstr "10.[0-9]" | findstr "Address" > ip.txt for /F "tokens=15 delims= " %%a in (ip.txt) do echo %%a>ip.txt REM Uploading the IP address: if not defined IPUpdaterPassword set /p IPUpdaterPassword=Enter your password: echo open %IPUpdaterHostname% > IPUpdaterFTP.txt echo %IPUpdaterUsername% >> IPUpdaterFTP.txt echo %IPUpdaterPassword% >> IPUpdaterFTP.txt echo put ip.txt >> IPUpdaterFTP.txt echo quit >> IPUpdaterFTP.txt ftp -s:IPUpdaterFTP.txt REM Tidying up: del ip.txt && del IPUpdaterFTP.txt set IPUpdaterHostname=&&set IPUpdaterUsername=&&set IPUpdaterPassword= If you want to hard-code the settings into the script you can trim those 4 lines near the top of course It's only a couple more lines to add a text file lookup so it would upload your location instead of your IP address. Edited March 7, 2009 by sahmeepee 1
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now