' Country filter maker ' Copyright (C) 2006 Unregistered DNS ' ' This program is free software; you can redistribute it and/or ' modify it under the terms of the GNU General Public License ' as published by the Free Software Foundation; either version 2 ' of the License, or (at your option) any later version. ' ' This program is distributed in the hope that it will be useful, ' but WITHOUT ANY WARRANTY; without even the implied warranty of ' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ' GNU General Public License for more details. ' ' You should have received a copy of the GNU General Public License ' along with this program; if not, write to the Free Software ' Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. Set argv = WScript.Arguments argc = argv.Count if (argc < 1) Then WScript.ECHO "Usage: countryfilter.vbs (Target Countries)" WScript.ECHO "" WScript.ECHO "(Target Countries): Target countries seperated with comma (ex. " + Chr(34) + "KR,CN,KP" + Chr(34) + ")." WScript.Quit end if TargetCountry = Split(argv(0), ",", -1, vbTextCompare) WScript.ECHO "# Country based filter from *NIC database." WScript.ECHO "# For APNIC, get from ftp://ftp.apnic.net/pub/apnic/stats/apnic/delegated-apnic-latest ." WScript.ECHO "# Created: " + CStr(Date()) + " " + CStr(Time()) WScript.ECHO "#" WScript.ECHO "# This filter detects access from contries;" TargetCountryStr="" for i=0 to UBound(TargetCountry) TargetCountryStr = TargetCountryStr + TargetCountry(i) + " " next WScript.ECHO "# " + TargetCountryStr WScript.ECHO "" WScript.ECHO "offline" WScript.ECHO "" while (not WScript.Stdin.AtEndOfStream) LineData = WScript.Stdin.ReadLine TextArray = Split(LineData, "|", -1, vbTextCompare) if (UBound(TextArray) >= 6) Then if (LCase(TextArray(2)) = "ipv4") Then ' check country found=0 for i=0 to UBound(TargetCountry) if (TargetCountry(i) = TextArray(1)) Then found=1 exit for end if next if (found = 1) Then ' calc subnet mask SubnetVal=1 SubnetBit=32 while (SubnetVal < CLng(TextArray(4))) SubnetVal = SubnetVal*2 SubnetBit = SubnetBit-1 wend if (SubnetBit < 8) Then Val=128 SubnetVal=0 for i=0 to SubnetBit-1 SubnetVal=SubnetVal+Val Val=Val/2 next SubnetMaskStr = CStr(SubnetVal) + ".0.0.0" elseif (SubnetBit < 16) Then Val=128 SubnetVal=0 for i=8 to SubnetBit-1 SubnetVal=SubnetVal+Val Val=Val/2 next SubnetMaskStr = "255." + CStr(SubnetVal) + ".0.0" elseif (SubnetBit < 24) Then Val=128 SubnetVal=0 for i=16 to SubnetBit-1 SubnetVal=SubnetVal+Val Val=Val/2 next SubnetMaskStr = "255.255." + CStr(SubnetVal) + ".0" else Val=128 SubnetVal=0 for i=24 to SubnetBit-1 SubnetVal=SubnetVal+Val Val=Val/2 next SubnetMaskStr = "255.255.255." + CStr(SubnetVal) end if WScript.ECHO "routing ip add filter name=" + Chr(34) + "ローカル エリア接続" + Chr(34) + " filtertype=INPUT srcaddr=" + TextArray(3) + " srcmask=" + SubnetMaskStr + " dstaddr=0.0.0.0 dstmask=0.0.0.0 proto=any" end if elseif (LCase(TextArray(2)) = "ipv6") Then ' do nothing elseif (LCase(TextArray(0)) = "2") Then ' database version WScript.ECHO "# Database version " + TextArray(2) end if end if wend WScript.ECHO "routing ip set filter name=" + Chr(34) + "ローカル エリア接続" + Chr(34) + " filtertype=INPUT action=FORWARD" WScript.ECHO "commit"