how can i do that with bash script or other way? i am using ubuntu 14.04 , ips will be added constantly
txt file will be look like this :
123.123.123.123
345.231.123.342
123.123.452.231
Thanks
how can i do that with bash script or other way? i am using ubuntu 14.04 , ips will be added constantly
txt file will be look like this :
123.123.123.123
345.231.123.342
123.123.452.231
Thanks
Last edited by feanor; 31st August 2017 at 16:35.
Something like (untested):
php banips.php
Edit: to constantly do this, simply make a endless loop around it and start it in a root screen session. Your home work.PHP Code:
$ips = file("ips.txt");
foreach ($ips as $ip) {
$cmd = "iptables -A INPUT -s $ip -j DROP";
echo "$cmd\n";
system($cmd);
}
timescale 0.01
./ban.sh: line 4: syntax error near unexpected token `('
./ban.sh: line 4: ` $ips = file("ips.txt");'
i made this taking example from google search but if i put in an infinite loop same ip will be banned and banned again am i right? how can i edit it to work properly?PHP Code:
#!/bin/bash
_input=/pathto/ips.txt
IPT=/sbin/iptables
egrep -v "^#|^$" $_input | while IFS= read -r ip
do
$IPT -A INPUT -s $ip -j DROP
done < "$_input"
------------
well , if we dont select ips start as ** with egrep/grep command and if we put ** starts of banned ips it can work properly. but i dont know how these commands work properly
Last edited by feanor; 1st September 2017 at 17:20.
it deletes ip.txt file when banned all ips , it works for mePHP Code:
#!/usr/bin/php -q
<?php
$TxtDosyaYol="/pathto/ip.txt";
while(1)
{
echo "working";
$IpListe=file_get_contents($TxtDosyaYol);
$IpArray=explode("\n", $IpListe);
for($i=0;$i<count($IpArray);$i++)
{
if(strlen($IpArray[$i])>5)
{
$Komut="/sbin/iptables -A INPUT -s ".$IpArray[$i]." -j DROP";
shell_exec($Komut);
}
}
unlink($TxtDosyaYol);
sleep(20); // wait 20 seconds
}
?>![]()
Last edited by feanor; 2nd September 2017 at 00:52.
kung foo man (2nd September 2017)
duplicate topic
https://killtube.org/showthread.php?...ighlight=banip
kubislav23 (6th September 2017)