shiryavsky

Mikrotik add ip rules from http

Aug 17th, 2015
237
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.29 KB | None | 0 0
  1. /tool fetch address=bl.cp1251.com host=bl.cp1251.com mode=http src-path=/netc.txt
  2. :delay 2
  3. :local i 0
  4. :local cfn ""
  5. :local fn ""
  6. :global maxfiles 0
  7. :set maxfiles [/file get [/file find name=netc.txt] contents];
  8. /ip route rule remove [/ip route rule find table=gov.no]
  9. :while ($i < $maxfiles) do={
  10. :set cfn ("/net" . $i . ".txt")
  11. :set fn ("net" . $i . ".txt")
  12. /tool fetch address=bl.cp1251.com host=bl.cp1251.com mode=http src-path=$cfn
  13. :delay 2
  14. :if ( [/file get [/file find name=$fn] size] > 0 ) do={
  15. :local content [/file get [/file find name=$fn] contents] ;
  16. :local contentLen [ :len $content ] ;
  17. :local lineEnd 0;
  18. :local line "";
  19. :local lastEnd 0;
  20. :do {
  21. :set lineEnd [:find $content "\n" $lastEnd ] ;
  22. :set line [:pick $content $lastEnd $lineEnd] ;
  23. :set lastEnd ( $lineEnd + 1 ) ;
  24. :if ( [:pick $line 0 1] != "#" ) do={
  25. :local entry [:pick $line 0 $lineEnd ]
  26. :if ( [:len $entry ] > 0 ) do={
  27. /ip route rule add dst-address=$entry action=lookup-only-in-table table=gov.no
  28. }
  29. }
  30. } while ($lineEnd < $contentLen)
  31. }
  32. :set i ($i+1);
  33. }
Advertisement
Add Comment
Please, Sign In to add comment