TTL value error
weirdvic opened this issue ยท 10 comments
I'm trying to scan my home router and get this error:
Mikrotik ip address: 192.168.27.1
Traceback (most recent call last):
File "main.py", line 62, in <module>
main(args)
File "main.py", line 31, in main
res = command.run_ssh(ssh_client)
File "/home/medusa/routeros-scanner/commands/dns.py", line 16, in run_ssh
sus_dns, recommendation = self.check_results_ssh(res, enabled)
File "/home/medusa/routeros-scanner/commands/dns.py", line 27, in check_results_ssh
if int(item['ttl'].partition('s')[0]) > 200000:
ValueError: invalid literal for int() with base 10: '3d21h23m50'
Device model is RouterBOARD 962UiGS-5HacT2HnT (Mikrotik hAP ac)
RouterOS version: 7.1.2
Steps to reproduce:
- run command
python3 main.py -i 192.168.1.1 -p 22 -u admin -ps routerpassword
I am having the same exact problem right now on 6.49.2 to 6.49.4.
@Andromerius you can flush dns cache before running the scan with command /ip dns cache flush
I guess the problem is in handling ttl value in /ip dns cache print detail
output which could be in #h#m#s format
Will try, thank you.
changing the line in dns.py to res = self._ssh_data_with_header(sshc, '/ip dns cache flush; /ip dns cache print detail without-paging')
works wonders and gives no errors. Thank you very much.
In my case flushing doesn't help, because the entry is the static entry I've put there for a reason with ttl=1d. Many users will have similar issues, there needs to be a proper fix.
Same issue on LTS 6.48.6
if int(item['ttl'].partition('s')[0]) > 200000:
ValueError: invalid literal for int() with base 10: '1d'
ok, thanks to an awesome guy at https://stackoverflow.com/a/41392376, i wrote the following fix (sorry im not good at git but i'll try commit the changes asap):
in commands/dns.py:
on line 3, add:
import re
remember, we want to find the size of the array for weeks, days, hours, mins, seconds. an array with weeks (w) would be size 5 because of 5 elements (w,d,h,m,s). days (d) would be 4, etc.
at the end of the file, add:
def hms(s):
l = list(map(int, re.split('[wdhms]', s)[:-1]))
if len(l) == 5:
return l[0]*604800 + l[1]*86400 + l[2]*3600 + l[3]*60 + l[4]
elif len(l) == 4:
return l[0]*86400 + l[1]*3600 + l[2]*60 + l[3]
elif len(l) == 3:
return l[0]*3600 + l[1]*60 + l[2]
elif len(l) == 2:
return l[0]*60 + l[1]
else:
return l[0]
change line 28 to:
if int(hms(item['ttl'].partition('s')[0])) > 200000:
HTH
ok, thanks to an awesome guy at https://stackoverflow.com/a/41392376, i wrote the following fix (sorry im not good at git but i'll try commit the changes asap): in commands/dns.py: on line 3, add:
import re
remember, we want to find the size of the array for weeks, days, hours, mins, seconds. an array with weeks (w) would be size 5 because of 5 elements (w,d,h,m,s). days (d) would be 4, etc.
at the end of the file, add:
def hms(s): l = list(map(int, re.split('[wdhms]', s)[:-1])) if len(l) == 5: return l[0]*604800 + l[1]*86400 + l[2]*3600 + l[3]*60 + l[4] elif len(l) == 4: return l[0]*86400 + l[1]*3600 + l[2]*60 + l[3] elif len(l) == 3: return l[0]*3600 + l[1]*60 + l[2] elif len(l) == 2: return l[0]*60 + l[1] else: return l[0]
change line 28 to:
if int(hms(item['ttl'].partition('s')[0])) > 200000:
HTH
@benskev That does not work. Line 28 should probably be if int(self.hms(item['ttl'].partition('s')[0])) > 200000:
, and even then I get:
if int(self.hms(item['ttl'].partition('s')[0])) > 200000:
TypeError: hms() takes 1 positional argument but 2 were given