POST method needed to send Params.bin to IP cam - vbscript

My IP cam sets itself back to default at times. I have a script that can run a VBS every two hours or so. I want the vbs to send the Params file to the cam even when I'm not there.
Here is what I've been working on all day. So far the best thing that happened was "Network Error"
Set IE = CreateObject("InternetExplorer.Application")
IE.Navigate("about:blank")
IE.AddressBar = False
IE.ToolBar = True
IE.StatusBar = True
IE.Resizable = False
IE.Visible = True
DataToPOST1 = "C:\Users\Garo\Desktop\params.bin"
Header = "Content-Type: application/x-www-form-urlencoded"
WScript.Sleep 5000
post = "/restore_params.cgi?"&"user=admin&pwd="""
IE.Navigate "192.168.1.17" & post, Nothing, Nothing, StringToBinary(DataToPOST1), Header
Function StringToBinary(str)
Dim tmpArr()
Dim i
ReDim tmpArr(Len(str))
For i = 1 Ro Len(str)
tmpArr(i-1) = CByte(AscB(Mid(str,i,1)))
Next
StringToBinary = tmpArr
End Function

Related

VBScript Fill Web Login Form

I can't figure out how can I fill Login Form with User and Pass and click on "OK" button.
I've tried several variants and nothing has been typed.
I made also I print screen with html code for each form.
On error resume next
Dim WshShell, objIE, ElementCol
Dim LinkHref
LinkHref = "https://www...."
Set WshShell = WScript.CreateObject("WScript.Shell")
Set objIE = CreateObject("InternetExplorer.Application")
objIE.Visible = False
objIE.Navigate LinkHref
wshShell.AppActivate objIE
Do While objIE.Busy
wscript.sleep 100
Loop
Set ElementCol = objIE.Document.getElementsByTagName("a")
For Each Link In ElementCol
If Link.innerHTML = "Continue to this website (not recommended)." Then
Link.Click
Exit For
End If
Next
objIE.Visible = True
objIE.Document.All.Item("S01LOGIN").value = "myusername"
'objIE.Document.getElementByName("S01LOGIN").Value = "myusername"
'objIE.document.getElementById("S01LOGIN").value = "myusername"
objIE.Document.All.Item("S02PASS").value = "mypass"
'objIE.Document.getElementByName("S02PASS").Value = "mypass"
'objIE.document.getElementById("S02PASS").value = "mypass"
I use IE11 and I think this is the problem

Vbscript to ping a list of machines and check if the IP-Addresses has changed and if they have changed send a Mail

I search for a Script that pings a List of machines and if a IP has changed send a warning mail. Hope somebody can help me.
Greets Mohrjon
Is the ping sufficient information to know that the IP address has changed? - what if the network goes down for a short period of time whilst the script is running?
Anyhow these are three subs i have which i have bodged together which should do what you need
Firstly i would iterate through a text file (csv) to get my ip address, and in this case the name and email
Sub Open_Master_File()
Do While objTextFile.AtEndOfStream <> True
strLine = objTextFile.ReadLine
'skip if comment line found
If inStr(1,strLine, "'") Then
ElseIf inStr(1,strLine, ",") Then
arrayMasterFile = split(strLine, ",")
strStoreName = arrayMasterFile(0)
strComputerIP = arrayMasterFile(1)
strEmailRecipient = arrayMasterFile(2)
'Call ping function to check for online/offline computers
Call Ping_Computer()
End If
Loop
'Release Memory
objTextFile.Close()
Set objTextFile = Nothing
Set objMasterFSO = Nothing
End Sub
next i ping to each of the ip's (btw this will only show if the ip is offline, can you guarantee that the ip is online all of the time?)
Sub Ping_Computer()
Set wshShell = CreateObject("WScript.Shell")
'Run the ping program 3 times, with a 2000ms delay on each, 0 = don't display cmd prompt
'All three pings must be successful for CBool = true
pingSuccessful = Not CBool(wshShell.run("ping -n 3 -w 2000 " & strComputerIP,0,True))
If pingSuccessful = True Then
Else
Call Send_EMail()
End If
'Release memory
Set wshShell = Nothing
End Sub
Send an email
Sub Send_Email()
Set objEmail = CreateObject("CDO.Message")
strSubject = ""
strEmailFrom = ""
strBody = ""
objEmail.Subject = strSubject
objEmail.From = strEmailFrom
objEmail.To = strEmailRecipient
'Use Microsoft schemas for emails
objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = cdoNTLM
objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = strServer
objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = cMailPort
objEmail.Configuration.Fields.Update
objEmail.Textbody = strBody
'Check if an error occurs during the send email process, do not stop program
On Error Resume Next
objEmail.Send
'error on send
If Err.Number <> 0 Then
Else
End If
'clear errors
On Error Goto 0
'Release Memory
Set objEmail = Nothing
End Sub

Logon to website the Login and password

I try to create a VBS script, what started automatically an website. This part could I solve.
But now I need to put in this script the function login as
And that is the point i stay stucked.
So I hope you can help me.
Here is the script I take to open the website
Dim objExplorer
Set objExplorer = WScript.CreateObject("InternetExplorer.Application")
Do While (objExplorer.Busy)
Wscript.Sleep 250
Loop
objExplorer.TheaterMode = False
objExplorer.AddressBar = True
objExplorer.MenuBar = True
objExplorer.StatusBar = True
objExplorer.ToolBar = False
objExplorer.Resizable = True
objExplorer.Height = 600
objExplorer.Width = 800
objExplorer.Left = 0
objExplorer.Top = 0
' objExplorer.FullScreen = True
objExplorer.Silent = False
objExplorer.Visible = True
objExplorer.Navigate https://mi-xxxxx-xxx-xxxxx.xxx.com/xxxxxxxxxxxxx/login.aspx
objExplorer.Login = User
ObjExplorer.Password = Password
wscript.sleep 6000
Set objShell = CreateObject("Wscript.Shell")
objShell.Run("taskkill /F /IM iexplore.exe /T")
Set objExplorer = nothing
I hope there is a easy way to come to an result.
Many thanks for your Help in this case.
best Regards
Martin
Instead of trying to automate the login via the GUI try inspecting the login process with something like Fiddler. That should give you the actual request that's passing the credentials from the client to the server. With that information you can use an XMLHttpRequest to automate the login:
url = "https://mi-xxxxx-xxx-xxxxx.xxx.com/xxxxxxxxxxxxx/login.asp"
user = "..."
pass = "..."
credentials = "username=" & user & "&password=" & pass
Set req = CreateObject("Msxml2.XMLHttp.6.0")
req.open "POST", url, False
req.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
req.send credentials
If req.status = 200 Then
'login successful
Else
'login failed
End If
You may need to adjust the url and credentials strings according to what Fiddler revealed. You may also need to encode username and/or password with something like this:
Function Encode(ByVal str)
Set re = New RegExp
re.Pattern = "[^a-zA-Z0-9_.~-]"
enc = ""
For i = 1 To Len(str)
c = Mid(str, i, 1)
If re.Test(c) Then c = "%" & Right("0" & Hex(Asc(c)), 2)
enc = enc & c
Next
Encode = enc
End Function
I find an great way to come to need result.
WScript.Sleep 5000
WshShell.SendKeys "******"
WScript.Sleep 3000
WshShell.SendKeys "{TAB}"
WScript.Sleep 3000
WshShell.SendKeys "*********"
WshShell.SendKeys "{TAB}"
WScript.Sleep 3000
WshShell.SendKeys "{ENTER}"
wscript.sleep 10000
So this task is solved.
many thanks for all your commands.
best Regards
martin

Post data with https does not get processed at Server side

I am having a VBScript which gets invoked from a 3rd party application, the script gets the data from the 3rd party application and opens the URL in an IE browser by passing the data in POST format. The script works fine when I use http as the protocol but the moment I use https, the server side code (request.getParameter("param1")) complains that it is not able to find the parameter in the request object. The script is called by passing the URL and the data. e.g. run.vbs https://xyz.com?param1=1234. Following is the vbscript for your kind perusal. Can you please let me know what I am missing when I am using https as the protocol. Any help is highly appreciated. Many thanks.
If WScript.Arguments.Count = 1 Then
uri = WScript.Arguments.Item(0)
'WScript.Echo "Arguments " & uri
Set WshNetwork = WScript.CreateObject("WScript.Network")
'WScript.Echo "Current User Name: " & WshNetwork.UserName
filename="C:\Documents and Settings\"+WshNetwork.UserName+"\Application Data\XYZ\Profiles\default\Settings.xml"
'WScript.Echo "Current User fileName: " & filename
Set xmlDoc = CreateObject("Microsoft.XMLDOM")
xmlDoc.Async = "False"
xmlDoc.Load(filename)
strQuery = "Agent"
Set colItem = xmlDoc.getElementsByTagname(strQuery)
For Each objItem in colItem
Agentid = objItem.getAttribute("Login")
'MsgBox "AgentId = " + AgentID
Next
'uri = uri+"^&agentid="+Agentid
uri = uri+"&agentid="+Agentid
pos = InStr(uri,"?")
extracteduri = Mid(uri,1,pos-1)
params = Mid(uri, pos+1)
postdata = Str2Bytes(params,"us-ascii")
header = "Content-Type: application/x-www-form-urlencoded"
Set IE = CreateObject("InternetExplorer.Application")
'IE.Navigate "about:blank"
'IE.AddressBar = True
'IE.ToolBar = True
'IE.StatusBar = True
IE.Visible = True
'WScript.Sleep 2000
Set shl = WScript.CreateObject("WScript.Shell")
shl.SendKeys "% X"
IE.Navigate extracteduri, Nothing, Nothing, postdata, header
Wscript.Quit
Else
Wscript.Echo "Usage: RunURL.vbs <URL to invoke>"
Wscript.Quit
End If
Function Str2Bytes(Text, CharSet)
Const adTypeText = 2
Const adTypeBinary = 1
'Create Stream object
Dim BinaryStream 'As New Stream
Set BinaryStream = CreateObject("ADODB.Stream")
'Specify stream type - we want To save text/string data.
BinaryStream.Type = adTypeText
'Specify charset For the source text (unicode) data.
If Len(CharSet) > 0 Then
BinaryStream.CharSet = CharSet
Else
BinaryStream.CharSet = "us-ascii"
End If
'Open the stream And write text/string data To the object
BinaryStream.Open
BinaryStream.WriteText Text
'Change stream type To binary
BinaryStream.Position = 0
BinaryStream.Type = adTypeBinary
'Ignore first two bytes - sign of
BinaryStream.Position = 0
'Open the stream And get binary data from the object
Str2Bytes = BinaryStream.Read
End Function
I am now using the below function to get the response from the server using https as the protocol and POST as the format but still the server is not able to see the parameter
Set req = CreateObject("MSXML2.ServerXMLHTTP")
'Set the below option to get rid of the "Certificate authority is invalid or
'incorrect, error code - 80072F0D" error
req.setOption 2, 13056
req.open "POST", extracteduri, False
req.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
encodedParams = Escape(params)
WScript.Echo "encodedParams: " & encodedParams
req.send encodedParams
WScript.Echo "req.responseText: " & req.responseText
Below are the encoded parameters
uui%3DU1%3D123456%26agentid%3D123456
The server still complains that the parameter is missing from the request object.
I am using the same script (XMLHTTP request) but I am encrypting the parameters using the Str2Bytes function (declared above)
Set req = CreateObject("MSXML2.ServerXMLHTTP")
req.setOption 2, 13056
req.open "POST", extracteduri, False
req.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
req.send postdata
WScript.Echo "req.responseText: " & req.responseText
I'd recommend using an XMLHTTPRequest instead of the Internet Explorer COM object. See here for an example. Note that you must encode special characters in the post data.
However, if you want to open the URL in IE anyway, you'd probably better stick with your original approach. In that case I'd check the server for more information about why the server side thinks it cannot find the parameter. Does the request even have a parameter named "param1"?

vbscript to send GET request using IE error

I've got the vbscript below which needs to send a GET request and then logoff the current user. The idea is to replace the default "logoff" start menu item with this script.
When I run it with cscript it throws an error on line 9,
HTTPGet = IE.document.documentelement.outerhtml
I don't understand what's wrong. Maybe I should wait to receive the response before logging off the user, but as the line above doesn't seem to work I logoff immediately.
TOKEN = "xxxxx"
Set IE = CreateObject("InternetExplorer.Application")
IE.visible = 0
IE.navigate "https://something.com/?action=create&token=" & TOKEN
Do While IE.Busy
WScript.Sleep 200 ' see the above notice of change
Exit Do ' prevents script host from going crazy waiting for IE
loop
HTTPGet = IE.document.documentelement.outerhtml
IE.quit
Set IE = Nothing
'WScript.Echo HTTPGet 'good for debugging. shows what you got back.
Dim objShell
Set objShell = WScript.CreateObject("WScript.Shell")
objShell.Run "C:\WINDOWS\system32\shutdown.exe -l"
If it matters this is for Windows XP only with IE 8.
Try out this code:
Set IE = CreateObject("InternetExplorer.Application")
IE.visible = 0
IE.navigate "https://host/?a=" & TOKEN
i = 1
Do While (IE.readyState <> 4)
WScript.Sleep 1000 ' see the above notice of change
i = i + 1
If (i > 10) Then
Exit Do
End If
loop
HTTPGet = IE.document.documentElement.outerHTML
IE.Quit()
Set IE = Nothing

Resources