1
I am trying to create a script to activate the QOS bandwidth control service of my router, but I am doing something wrong because I can’t keep the connection after making a POST request.
local host = '192.168.0.1'
local headers = [[]]
local LuaSocket = require("socket")
client = LuaSocket.connect(host, 80)
headers = [[Host: 192.168.0.1
Connection: keep-alive
Content-Type: application/x-www-form-urlencoded
Content-Length: 39
Username=admin&checkEn=0&Password=admin]]
client:send("POST /LoginCheck " .. headers)
print("First request")
while 1 do
r, err = client:receive()
if err then
break
end
print(r)
end
headers = [[Host: 192.168.0.1
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: pt-BR,pt;q=0.8,en-US;q=0.5,en;q=0.3
Accept-Encoding: gzip, deflate
Referer: http://192.168.0.1/index.asp
Cookie: language=pt; admin:language=pt
Connection: keep-alive]]
client:send("GET /goform/trafficForm?GO=net_tc.asp&tc_enable=1&up_Band=12800&down_Band=12800&cur_number=2&tc_list_1=80,100,100,1,50,2000,1,1&tc_list_2=80,101,150,1,1,50,1,1 HTTP/1.0" .. headers)
print("Second request")
while 1 do
r, err = client:receive()
if err then
break
end
print(r)
end
client:close()
When performing, I have this
First request
HTTP/1.0 302 Redirect
Server: GoAhead-Webs
Date: Wed Aug 03 05:09:46 2016
Set-Cookie: admin:language=pt; path=/
Pragma: no-cache
Cache-Control: no-cache
Content-Type: text/html
Location: index.asp
Second request
Through the browser, I have this answer from POST in /Logincheck
Cache-Control: no-cache
Content-Type: text/html
Date: Wed Aug 03 05:13:15 2016
Location: index.asp
Pragma: no-cache
Server: GoAhead-Webs
Set-Cookie: admin:language=pt; path=/
From what I saw, he logs in, but I don’t know how to maintain the connection to get the GET order that would activate the bandwidth control.
NOTE: To access any page of the router, I need to login to the page 192.168.0.1/login.Asp, who makes a POST request to 192.168.0.1/Logincheck, and if successfully performed, redirect to 192.167.0.1/index.Asp and then you can access the other pages of the same.