Manage the AI Thai Router Web authentication account script

Source: Internet
Author: User

The Hayter routing of the isolated PPPoE router in the dormitory cannot establish a separate account for managing Web authentication, so a script management Web authentication account is written.


Add the core code of the Web authentication account

Func addhotspotuser (); Gets the number of accounts from the router dim  $webHTML  = inetread (' http://'  & $ routeradminname &  ': '  &  $RouterAdminPSW  &  ' @ '  & $ routerip &  '/webauthserver.asp ',  9)    If  $webHTML  =  "  Then  msgbox (32,  "Warning",  "Connection router timeout or login router user name password error. ")   Exit   Else   $webHTML  = binarytostring ($webHTML); match Totalrecs =, that is, the number of accounts $webauthnamescounts = stringregexp ($webHTML,  ' var\stotalrecs\= ([^\ "]+) \;var ',  1)         If  @error  <> 0 thenmsgbox (32,  " Warning ", " regular match webauthnamescounts account error, error= " &  @error) exit else$webauthnamescount =   $WebAuthNamesCounts [0] endif   endif; Get account number from log dim  $hotspotUserName  =  0,  $remainingCount  = 0,  $logAccouts  = 0for  $i  = 1 To  $totalAccountLocal   $fLine  = filereadline ($LogFile     $i)    If  @error  <> 0 then  msgbox (32,  "Warning",   "An error occurred while opening the log file."  &  @error,  10)   Exit   EndIfLocal  $fLineDay  =  Stringleft ($fLine,  10)    If  $fLineDay  =  @YEAR  &  "-"   &  @MON  &  "-"  &  @MDAY  Then   $logAccouts  += 1    Else  ExitLoop   EndIfNext; if the number of accounts obtained on the router differs from the number of records obtained on the log, It is possible that someone directly logged in to the router added the account if  $WebAuthNamesCount  <>  $logAccouts  then   msgbox ( 32,  "Warning",  "the number of records and logs on the router is different, please contact the IT department")    ExitElse    $remainingCount  =  49 -  $WebAuthNamesCount; The number of endif left after this account is added; Find the last account name   Local  $aTemp  =  Stringregexp ($webHTML, &nbsP; " (? <=\ (\) \;var\stotalrecs\;\n). * (? =\;var\stotalrecs\=) ",  1); regular match      if @ error <> 0 and  $WebAuthNamesCount  = 0 Then; Regular match does not indicate that there is no account, you will add the first account $ Lastwebauthname = 0 elseif isarray ($aTemp)  ThenLocal  $aListTemp  =  Stringsplit ($aTemp [0],  ";"); for  $i  = 2 to ubound ($aListTemp)  -1 Step 6; all accounts; match the last webauthname$ Webauthnames = stringregexp ($aListTemp [UBound ($aListTemp)  - 5],  ' webauthnames\[\d*\]\ S\=\s\ "([^\"]+) \ "'",  1)         If  @error  <> 0  thenmsgbox (32,  "Warning",  "regular match webauthnames account error, error="  &  @error) exit else$ lastwebauthname =  $WebAuthNames [0] endif elsemsgbox (32,  "Warning",  " Error matching webauthnames array ") Exit endifif stringisdigit ($lastWebAuthName)  then   $ Hotspotusername =  $lastWebAuthName  + 1EndIfIf  $hotspotUserName  = 13 Then     $hotspotUserName  = 15endif$hotspotuserpsw = random (100000, 999999, 1 ); Use a 6-bit random number to do the password; write the log first, otherwise you have added the account path but write log error trouble, by the way first check whether the log is allowed to write, if not allow to write to log exit _filewritelog ($LogFile,  $UserName   &  " Add HotSpot Account "  &  $hotspotUserName  &  "  Password is   &  $hotspotUserPSW,  0)    If  @error   <> 0 then  msgbox (32,  "Warning",  "open log file has an error or is not writable. " &  @error,  10)   Exit   EndIf; Connect router Add account $ohttp =  Objcreate ("Microsoft.XMLHTTP") $oHTTP. Open ("POST",  "http://"  &  $RouterAdminName  &   ":"  &  $RouterAdminPSW  &  "@"  &  $RouterIP  &  "/ Goform/formwebauthconfig ",  false) $oHTTP. setRequestHeader (" CAche-control ", " No-cache ") $oHTTP. setRequestHeader (" Content-type "," application/x-www-form-urlencoded ") $ Ohttp.setrequestheader ("Referer", "http://"  &  $RouterIP  & "/webauth_edit.asp") $oHTTP. Send ("Action=add&instindex=&authname="  &  $hotspotUserName  &  "&authnameold= &authpasswd= " &  $hotspotUserPSW  & " &authip=&authtimestart=yyyy-mm-dd &begindate=&authtimestop=yyyy-mm-dd&enddate=&authtimetotal=0.0&remark= ");p ost key Data $otext  = binarytostring ($oHTTP. responsebody)  ; processing responsetext will be garbled, with responsebody can be; action=add&instindex=&authname=test10&authnameold=&authpasswd=abc&authip=;& authtimestart=yyyy-mm-dd&begindate=&authtimestop=yyyy-mm-dd&enddate=&authtimetotal=9.5& REMARK=9.5%D0%A1%CA%B1; Consolewrite ($oText) if stringinstr ($oText,  ' user name already exists ')  <> 0 Then; already registered     _filewritetoline ($LogFile, 1,  "",  1); Delete the above add log record    msgbox (0,  "",  "the user name already exists error, please add again. ") elseif  $oText  = " " Then; return empty, can be processed as timed out. It is also possible that the data submitted incorrectly results in an empty    msgbox (0,  "",  "timeout error. May have added an account to the router, please contact the IT department to view. ") Else$hdiff = _datediff (  ' h ', _nowcalc (),   _dateadd (' d ',  1, _nowcalcdate ())  &  " 00:00:00"); calculate the number of hours left today; return information such as account password MsgBox (0,  "Fiori wifi",   @CRLF  &  "Login ID:"  &  $hotspotUserName  &  @CRLF  &  "Login password is:"  &  $hotspotUserPSW  &  @CRLF  &  @CRLF  &  "remaining available for Internet time:"   &  $hDiff  &  hours  &  @CRLF  &  @CRLF  &  "The number of available accounts remaining today: " &  $remainingCount  &  @CRLF  & " is valid on the day of the account, please follow the relevant Internet rules. ") Endifendfunc;==>addhotspotuser

Periodically delete all Web authentication account codes every day

To test whether the router is connected, consider adding a notification to the administrator dim  $testConnect  = testconnect ($routerIP,  $routerPort) if $ Testconnect = 0 then   msgbox (32,  "error",  "Cannot access the router! ",  10)    exitendif#--------------------------------------------------------$ff  =  inetread ('/http '  &  $routerAdminName  &  ': '  &  $routerAdminPSW  &  ' @ '  &  $routerIP  &  '/goform/formwebauthlistdelall ',  9); $ff  = binarytostring ($FF); Consolewrite ($FF) exit#-----------------------------------------------------------func testconnect ($ip,   $port) Tcpstartup () $Socket  = tcpconnect ($ip,  $port)    If  $socket   <> 1 and  $socket  <> -1 and  $socket  <> 2  then  return 1   else  return 0    Endiftcpclosesocket ($Socket) EndFunc;==>testconnect 


This article is from the "Temporary blog" blog, please be sure to keep this source http://gzzhang.blog.51cto.com/5312382/1546932

Manage the AI Thai Router Web authentication account script

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.