# To block ip address

**URL:** <https://community.unix.com/t/to-block-ip-address/237377>\
**Category:** Shell Programming and Scripting\
**Created:** [April 9, 2009, 3:27pm UTC](https://community.unix.com/t/to-block-ip-address/237377 "2009-04-09T15:27:39Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![gsiva](https://community.unix.com/letter_avatar/gsiva/32/5_5575768a8748004e209b776fc1b2916d.png) [@gsiva](https://community.unix.com/u/gsiva)\
**Post date:** [April 9, 2009, 3:27pm UTC](https://community.unix.com/t/to-block-ip-address/237377/1 "2009-04-09T15:27:39Z")

</div>

Hi,

I need to block a ip address without logging to the server not for a single server for more number of servers. I use the tool " apf" to block an ip

apf -d \<Ipaddress\>

Is this can be done with the shell script.?

---

<div class="post-metadata">

**Author:** ![Neo](https://community.unix.com/user_avatar/community.unix.com/neo/32/22838_2.png) [@Neo](https://community.unix.com/u/Neo)\
**Post date:** [April 9, 2009, 3:51pm UTC](https://community.unix.com/t/to-block-ip-address/237377/2 "2009-04-09T15:51:00Z")

</div>

> [@gsiva](#):
>
> Is this can be done with the shell script.?

Yes, of course.

---

<div class="post-metadata">

**Author:** ![gsiva](https://community.unix.com/letter_avatar/gsiva/32/5_5575768a8748004e209b776fc1b2916d.png) [@gsiva](https://community.unix.com/u/gsiva)\
**Post date:** [April 9, 2009, 4:01pm UTC](https://community.unix.com/t/to-block-ip-address/237377/3 "2009-04-09T16:01:28Z")

</div>

Can I have the script to do this, please.. . I am not much familiar in shell scripting ...

---

<div class="post-metadata">

**Author:** ![Neo](https://community.unix.com/user_avatar/community.unix.com/neo/32/22838_2.png) [@Neo](https://community.unix.com/u/Neo)\
**Post date:** [April 9, 2009, 4:05pm UTC](https://community.unix.com/t/to-block-ip-address/237377/4 "2009-04-09T16:05:17Z")

</div>

What shell are you using?

---

<div class="post-metadata">

**Author:** ![gsiva](https://community.unix.com/letter_avatar/gsiva/32/5_5575768a8748004e209b776fc1b2916d.png) [@gsiva](https://community.unix.com/u/gsiva)\
**Post date:** [April 9, 2009, 4:12pm UTC](https://community.unix.com/t/to-block-ip-address/237377/5 "2009-04-09T16:12:19Z")

</div>

bash shell

---

<div class="post-metadata">

**Author:** ![Neo](https://community.unix.com/user_avatar/community.unix.com/neo/32/22838_2.png) [@Neo](https://community.unix.com/u/Neo)\
**Post date:** [April 9, 2009, 4:18pm UTC](https://community.unix.com/t/to-block-ip-address/237377/6 "2009-04-09T16:18:33Z")

</div>

... and what do you want the script to do? what are the inputs and outputs required?

---

<div class="post-metadata">

**Author:** ![gsiva](https://community.unix.com/letter_avatar/gsiva/32/5_5575768a8748004e209b776fc1b2916d.png) [@gsiva](https://community.unix.com/u/gsiva)\
**Post date:** [April 9, 2009, 4:36pm UTC](https://community.unix.com/t/to-block-ip-address/237377/7 "2009-04-09T16:36:07Z")

</div>

Once if I run the script, it should ask me for the ip address to be blocked.  
And, When I enter the ip address, it should be get blocked in all the server that are listed in the script. Thats it nothing much...

---

<div class="post-metadata">

**Author:** ![Neo](https://community.unix.com/user_avatar/community.unix.com/neo/32/22838_2.png) [@Neo](https://community.unix.com/u/Neo)\
**Post date:** [April 9, 2009, 4:38pm UTC](https://community.unix.com/t/to-block-ip-address/237377/8 "2009-04-09T16:38:33Z")

</div>

OK, that is very easy.

I suggest you search the forums a bit and you will find many examples of similar code, then write you own script and post it. Folks will help you if you do the initial work.

---

<div class="post-metadata">

**Author:** ![gsiva](https://community.unix.com/letter_avatar/gsiva/32/5_5575768a8748004e209b776fc1b2916d.png) [@gsiva](https://community.unix.com/u/gsiva)\
**Post date:** [April 9, 2009, 4:45pm UTC](https://community.unix.com/t/to-block-ip-address/237377/9 "2009-04-09T16:45:28Z")

</div>

I have already searched, but I could not able to find out any.... after then I posted ..

---

<div class="post-metadata">

**Author:** ![Neo](https://community.unix.com/user_avatar/community.unix.com/neo/32/22838_2.png) [@Neo](https://community.unix.com/u/Neo)\
**Post date:** [April 9, 2009, 4:50pm UTC](https://community.unix.com/t/to-block-ip-address/237377/10 "2009-04-09T16:50:04Z")

</div>

I think there are many many examples of code here that take an input argument and use that argument in the script.

You need to search more 😃

If you can't find it (maybe you are not good at keyword searches), you can search the net for a bash tutorial and at least attempt to write this very trivial script yourself first.

Then, post what you have written and folks will help you.

---

<div class="post-metadata">

**Author:** ![gsiva](https://community.unix.com/letter_avatar/gsiva/32/5_5575768a8748004e209b776fc1b2916d.png) [@gsiva](https://community.unix.com/u/gsiva)\
**Post date:** [April 9, 2009, 4:52pm UTC](https://community.unix.com/t/to-block-ip-address/237377/11 "2009-04-09T16:52:22Z")

</div>

Ok Sure,, I will try and get up with the script...
