hi, can anyone help me write a script which will get addresses from this list https://any.andryou.com/oisdhosts.txt and enter them into static dns with the address 127.0.0.1?
See this thread for help:
I’m not a programmer but i put down a script python to insert dns static from web link
filepath = 'tmpHosts.txt'
url = 'https://any.andryou.com/oisdhosts.txt'
import urllib.request
with urllib.request.urlopen(url) as response:
testfile = response.read()
file = open(filepath,'wb')
file.write(testfile)
file.close()
ip_mikrotik = '192.168.33.99'
port_mikrotik= '22'
username_mikrotik= 'admin'
password_mikrotik = 'admin'
import paramiko
ssh=paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect(ip_mikrotik,port_mikrotik,username_mikrotik,password_mikrotik)
NewHost = '127.0.0.1 '
try:
with open(filepath) as fp:
for cnt in fp:
if cnt[:8]=='0.0.0.0 ':
Name = cnt[8:]
cmd_mikrotik = '/ip dns static add address='+NewHost+'name='+Name
try:
stdin,stdout,stderr=ssh.exec_command(cmd_mikrotik)
print (cmd_mikrotik)
except:
print('Error SSH')
except:
print('Error read file')
ssh.close()
Marcello
thanks for the help,
is there a chance to create a script entirely processed by mikrotik?