Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!


Need help with IP Block script
New on LowEndTalk? Please Register and read our Community Rules.

All new Registrations are manually reviewed and approved, so a short delay after registration may occur before your account becomes active.

Need help with IP Block script

BlazeMuisBlazeMuis Member
edited April 2012 in General

I'm trying to make an IP Ban Script, so my Admins of my Gameserver can easely ban people by IP

I want it like this: ./ipban.sh IPHERE

I already got this:

#!/bin/sh
if [ -z "$ip" ]
then
executable=$ip
shift
while [ -n "ip" ]
do
iptables -A INPUT -s $ip -j DROP
done
fi

But when u do ./ipban.sh IPHERE i get this:

Bad argument `DROP'
Try `iptables -h' or 'iptables --help' for more information.

Can someone help me with this?

Comments

  • @joodle said: Can someone help me with this?

    Use /etc/hosts.deny, line-based like regular hosts file, much simpler.

  • dmmcintyre3dmmcintyre3 Member
    edited April 2012
    #!/bin/bash
    route add $1 lo
    echo "route add $1 lo" >> /etc/rc.local #re-blocks IP on system startup
    

    Usage: ./filename.sh ip.addr.to.ban

    Thanked by 1TheHackBox
  • AmfyAmfy Member
    edited April 2012

    Mustn't you make anything like $ip=$1? $1 would be "IPHERE"

    Or replace "$ip" in your script with "$1".

    Thanked by 1netomx
  • Doesn't display any errors anymore
    But now it doesn't block IP's...

  • AmfyAmfy Member

    What have you exactly done? What does iptables -L show?

  • BlazeMuisBlazeMuis Member
    edited April 2012

    I changed the $ip to $1

    Output from iptables -L

    iptables -L
    Chain INPUT (policy ACCEPT)
    target     prot opt source               destination
    DROP       all  --  217.147.94.149       anywhere
    DROP       all  --  74-115-1-42.anchorfree.com  anywhere
    DROP       all  --  95.154.250.119       anywhere
    DROP       all  --  78.129.189.55        anywhere
    DROP       all  --  199-255-209-75.anchorfree.com  anywhere
    DROP       all  --  199-255-209-76.anchorfree.com  anywhere
    
    Chain FORWARD (policy ACCEPT)
    target     prot opt source               destination
    
    Chain OUTPUT (policy ACCEPT)
    target     prot opt source               destination

    These are the IP's i banned manually with iptables -A INPUT -s iphere -j DROP
    Not with the script

  • AmfyAmfy Member

    Hmm, looks like that you banned already some IPs and it should work. You could try to reset iptables with iptables -F and /etc/init.d/iptables restart, but it should work already. - Is it an openvz container? Don't know why but had already some problems with it and iptables. Iptables showed banned IPs but it haven't blocked them.

  • @Amfy

    Those Ip's i didn't ban with the script :)
    Just via console, with iptables -A INPUT -s IP -j DROP

  • AmfyAmfy Member

    @joodle: Don't know what your problem exactly is, but it makes no difference if you use the script or just the console with your iptables command.

  • @amfy

    It's easier for my Admins to just give them a script, instead of them keep asking me for the command line

  • AmfyAmfy Member

    @joodle

    My comment above was the answer to "Those Ip's i didn't ban with the script :)"

    But do whatever you want.

Sign In or Register to comment.