Advertisement
Guest User

Untitled

a guest
Jun 24th, 2019
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.81 KB | None | 0 0
  1. config system accprofile
  2. edit "prof_admin"
  3. set mntgrp read-write
  4. set admingrp read-write
  5. set updategrp read-write
  6. set authgrp read-write
  7. set sysgrp read-write
  8. set netgrp read-write
  9. set loggrp read-write
  10. set routegrp read-write
  11. set fwgrp read-write
  12. set vpngrp read-write
  13. set utmgrp read-write
  14. set wanoptgrp read-write
  15. set endpoint-control-grp read-write
  16. set wifi read-write
  17. next
  18. end
  19. config system interface
  20. edit "port1"
  21. set vdom "root"
  22. set ip 192.168.0.150 255.255.255.0
  23. set allowaccess ping https ssh http telnet
  24. set type physical
  25. set role wan
  26. set snmp-index 1
  27. next
  28. edit "port2"
  29. set vdom "root"
  30. set type physical
  31. set role wan
  32. set snmp-index 2
  33. next
  34. end
  35.  
  36. arquivo = "config.txt"
  37. inicio = "config system interface"
  38. fim = "end"
  39. copiar = False
  40. trecho = []
  41.  
  42. arq = open(arquivo, "r")
  43.  
  44. for linha in arq :
  45.  
  46. if copiar == True:
  47. trecho.append(linha)
  48.  
  49. if inicio in linha:
  50. copiar = True
  51. trecho.append(linha)
  52.  
  53. if fim in linha:
  54. copiar = False
  55.  
  56. arq.close()
  57.  
  58. for linha in trecho:
  59. print(linha)
  60.  
  61. config system interface
  62.  
  63. edit "port1"
  64.  
  65. set vdom "root"
  66.  
  67. set ip 192.168.0.150 255.255.255.0
  68.  
  69. set allowaccess ping https ssh http telnet
  70.  
  71. set type physical
  72.  
  73. set role wan
  74.  
  75. set snmp-index 1
  76.  
  77. next
  78.  
  79. edit "port2"
  80.  
  81. set vdom "root"
  82.  
  83. set type physical
  84.  
  85. set role wan
  86.  
  87. set snmp-index 2
  88.  
  89. next
  90.  
  91. end
  92.  
  93. configuracoes = [] # guarda todos os trechos 'config system interface'
  94. with open('arquivo_de_configuracao.txt') as file:
  95. dentro_do_bloco = False # verifica se está dentro de um bloco de config desejado
  96. config = [] # guarda a config atual
  97. for linha in file: # lê o arquivo linha a linha
  98. linha = linha.strip('n') # retirar quebra de linha
  99. if linha == 'config system interface':
  100. dentro_do_bloco = True # iniciou o bloco
  101. config.append(linha)
  102. elif dentro_do_bloco:
  103. config.append(linha)
  104. if linha == 'end':
  105. dentro_do_bloco = False # terminou o bloco
  106. # junta tudo e guarda na lista de configs encontradas
  107. configuracoes.append('n'.join(config))
  108. config = []
  109.  
  110. # imprime as configurações encontradas
  111. for c in configuracoes:
  112. print(c)
  113.  
  114. import re
  115.  
  116. with open('/tmp/arq.txt') as file:
  117. conteudo = file.read()
  118. r = re.compile('^config system interface$(?:(?!^end$).)+^end$', re.MULTILINE | re.DOTALL)
  119. configuracoes = r.findall(conteudo)
  120.  
  121. # imprime as configurações encontradas
  122. for c in configuracoes:
  123. print(c)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement