# Fetch URL file then execute the file

**URL:** <https://forum.mikrotik.com/t/fetch-url-file-then-execute-the-file/149100>\
**Category:** Scripting\
**Created:** [May 14, 2021, 2:45am UTC](https://forum.mikrotik.com/t/fetch-url-file-then-execute-the-file/149100 "2021-05-14T02:45:01Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![MarHazK](https://forum.mikrotik.com/user_avatar/forum.mikrotik.com/marhazk/32/1870_2.png) [@MarHazK](https://forum.mikrotik.com/u/MarHazK)\
**Post date:** [May 14, 2021, 2:45am UTC](https://forum.mikrotik.com/t/fetch-url-file-then-execute-the-file/149100/1 "2021-05-14T02:45:01Z")

</div>

I have server (CentOS) that gather all the active blacklisted IPs (most of the time that attempt SSH logins/spamhaus/RBL listed/etc.) and I have the blacklist.php that will generate that blacklisted IPs the hosted under Apache+PHP.

What I am going to do is, that blacklist.php will generate all the Mikrotik command like the following:

```plaintext
/ip firewall address-list add list=blacklist address=<blacklisted IPs from DB>

```

Then, that IPs will be listed under my Mikrotik’s address list named “blacklist”, and my Rules already add DROP the incoming/outgoing traffic into that rules.

However, I am clueless how to run the generated file into Mikrotik. Anyone know how to do this into the script?  
Lets say the script’s scenario is like this:

1. Execute /tool fetch url=“[http://blablabla/servercmd.php](http://blablabla/servercmd.php)” http-method=post http-data=“op=mikrotik” output=“runremotescript”
2. Execute all the generated Mikrotik’s commands in runremotescript

the runremotescript will be like this:

1. /ip firewall address-list add list=blacklist address=\<generated from [http://blablabla/servercmd.php](http://blablabla/servercmd.php)\>  
Example:

```plaintext
/ip firewall address-list add list=blacklist address=123.25.25.128

```

TQ

---

<div class="post-metadata">

**Author:** ![rextended](https://forum.mikrotik.com/user_avatar/forum.mikrotik.com/rextended/32/67729_2.png) [@rextended](https://forum.mikrotik.com/u/rextended)\
**Post date:** [May 14, 2021, 7:00am UTC](https://forum.mikrotik.com/t/fetch-url-file-then-execute-the-file/149100/2 "2021-05-14T07:00:57Z")

</div>

The forum is FULL of example, use SEARCH function first:

[http://forum.mikrotik.com/t/importing-ip-list-from-file/143071/8](http://forum.mikrotik.com/t/importing-ip-list-from-file/143071/8)  
[http://forum.mikrotik.com/t/help-with-error-in-script-to-import-the-ipv4-full-bogons-list-from-www-team-cymru-org/113429/4](http://forum.mikrotik.com/t/help-with-error-in-script-to-import-the-ipv4-full-bogons-list-from-www-team-cymru-org/113429/4)

But I prefer mine because file size limit are little, and I prefer read IP than read replicated commands that use more space than single IP,

---

<div class="post-metadata">

**Author:** ![MarHazK](https://forum.mikrotik.com/user_avatar/forum.mikrotik.com/marhazk/32/1870_2.png) [@MarHazK](https://forum.mikrotik.com/u/MarHazK)\
**Post date:** [May 14, 2021, 2:10pm UTC](https://forum.mikrotik.com/t/fetch-url-file-then-execute-the-file/149100/3 "2021-05-14T14:10:59Z")

</div>

thanks.. solved
