SSH Access - Login delay
Posted: Sat Mar 20, 2021 2:39 pm
BiPAC 8800AXL R2, Firmware 2.52.d15
I am trying to capture the ADSL line performance stats regularly, to pin down the reason why the ISP seems to be varying my speeds a lot.
I have used a simple routine using AutoIT, on Windows 10, to TelNet into the 8800 every 5 minutes and capture WAN SHOW and ADSL INFO --STATS results as strings and parse the required data I need. All good (and helped me find an LED lamp which increased the noise on my line by 6dB when on!).
I am concerned about the network carrying main router login credentials in clear text every 5 minutes over WiFi, so switched the routine to use SSH. I have utilised a function block written to support SSH access but I don't fully understand how it works, unfortunately.
The 8800 always rapidly responds to the SSHConnect() request to open a socket. It suffers, however, from the variable delay that the 8800 has between entering the valid password and the return of the command prompt, which is " > ". This delay is usually 3 to 4 seconds but can be up to several minutes. This delay is also visible when using PuTTY to test the commands manually. As far as I can tell, the router does always come back eventually but it misses reporting points if over the 5 minute cycle time.
Once logged in, the commands 'wan show', 'adsl info --stats' and 'syslog dump' respond immediately, as does 'logout'. Searching the AutoIT forums suggests that I may have a problem with reverse DNS timeouts (?) and that the solution is to turn 'DNS off' in the SSH server. Am I on the right track?
I also discovered (RTFM?) that there is a setting within the 8800 for setting Remote Access on. During my experiments, HTML was the only option enabled (SSH still worked, however) but enabling SSH made no difference. I should add that I am only considering doing this over my network, not over the web.
Is there any other way to securely access the router to extract these stats?
Thanks
John
Extract of code ==>
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
; PART ONE - Interrogate Modem/Router
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
_Log("Reset Log/Report files")
FileDelete($LogFilename)
;FileDelete($OutFilename) ; Need to set a report file management regime
$WAN = "Not Defined"
$ADSL = "Not Defined"
$LoggedIn = "No"
; Start the service and register OnAutoItExit to be called when the script is closed, to ensure that the session is closed correctly.
_Log("Opening Communications")
_SSHStartup()
OnAutoItExitRegister("OnAutoItExit")
;Connect to modem/router telnet port
_Log("Connecting")
Local $hTimer = TimerInit()
Local $RouterIP = _SSHConnect($DeviceIP, "22", $DeviceUserName, $DevicePassword)
;Check that modem/router is responding
If $RouterIP = 0 Then
$Connected = "No"
_Log("Failed to connect")
Else
$Connected = "Yes"
_Log("Connected: (" & $RouterIP & ")")
; Wait for prompt
$i = 0
Do
Sleep(3000)
$TCPRecv = _SSHRecv($RouterIP, "5000")
_Log($TCPRecv)
$i = $i + 1
Until $TCPRecv = " > " or $i = 10
If $TCPRecv = " > " Then
$LoggedIn = "Yes"
_Log("Logged in")
; Send WAN SHOW command
Sleep(1000)
_SSHSend($RouterIP, "wan show" & @CRLF)
Sleep(100)
$TCPRecv = _SSHRecv($RouterIP, "5000")
Extract ends ==>
I am trying to capture the ADSL line performance stats regularly, to pin down the reason why the ISP seems to be varying my speeds a lot.
I have used a simple routine using AutoIT, on Windows 10, to TelNet into the 8800 every 5 minutes and capture WAN SHOW and ADSL INFO --STATS results as strings and parse the required data I need. All good (and helped me find an LED lamp which increased the noise on my line by 6dB when on!).
I am concerned about the network carrying main router login credentials in clear text every 5 minutes over WiFi, so switched the routine to use SSH. I have utilised a function block written to support SSH access but I don't fully understand how it works, unfortunately.
The 8800 always rapidly responds to the SSHConnect() request to open a socket. It suffers, however, from the variable delay that the 8800 has between entering the valid password and the return of the command prompt, which is " > ". This delay is usually 3 to 4 seconds but can be up to several minutes. This delay is also visible when using PuTTY to test the commands manually. As far as I can tell, the router does always come back eventually but it misses reporting points if over the 5 minute cycle time.
Once logged in, the commands 'wan show', 'adsl info --stats' and 'syslog dump' respond immediately, as does 'logout'. Searching the AutoIT forums suggests that I may have a problem with reverse DNS timeouts (?) and that the solution is to turn 'DNS off' in the SSH server. Am I on the right track?
I also discovered (RTFM?) that there is a setting within the 8800 for setting Remote Access on. During my experiments, HTML was the only option enabled (SSH still worked, however) but enabling SSH made no difference. I should add that I am only considering doing this over my network, not over the web.
Is there any other way to securely access the router to extract these stats?
Thanks
John
Extract of code ==>
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
; PART ONE - Interrogate Modem/Router
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
_Log("Reset Log/Report files")
FileDelete($LogFilename)
;FileDelete($OutFilename) ; Need to set a report file management regime
$WAN = "Not Defined"
$ADSL = "Not Defined"
$LoggedIn = "No"
; Start the service and register OnAutoItExit to be called when the script is closed, to ensure that the session is closed correctly.
_Log("Opening Communications")
_SSHStartup()
OnAutoItExitRegister("OnAutoItExit")
;Connect to modem/router telnet port
_Log("Connecting")
Local $hTimer = TimerInit()
Local $RouterIP = _SSHConnect($DeviceIP, "22", $DeviceUserName, $DevicePassword)
;Check that modem/router is responding
If $RouterIP = 0 Then
$Connected = "No"
_Log("Failed to connect")
Else
$Connected = "Yes"
_Log("Connected: (" & $RouterIP & ")")
; Wait for prompt
$i = 0
Do
Sleep(3000)
$TCPRecv = _SSHRecv($RouterIP, "5000")
_Log($TCPRecv)
$i = $i + 1
Until $TCPRecv = " > " or $i = 10
If $TCPRecv = " > " Then
$LoggedIn = "Yes"
_Log("Logged in")
; Send WAN SHOW command
Sleep(1000)
_SSHSend($RouterIP, "wan show" & @CRLF)
Sleep(100)
$TCPRecv = _SSHRecv($RouterIP, "5000")
Extract ends ==>