윈도우 해외 IP 차단하기
우선은 아래 링크에서 국가별IP목록이 있는 파일을 받아줍니다.
파워쉘 스크립트 작성
아래의 내용에서 차단하기를 원하는 국가와 GeoIPCountryWhois.csv파일 경로를 바꾸신 후 문서 편집기로 작성 후
GeoIPCountryWhois.csv파일이 있는곳에 .ps1파일로 저장하면 됩니다.
코드는 아래 텍스트 파일을 받으세요.
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950 #############Config#################$countryCode="CN" #차단할 나라의 CountryCode#$geoIPcvsPath="c:\GeoIPCountryWhois.csv"$geoIPcvsPath="\GeoIPCountryWhois.csv"$ruleName="blockCountry"#############Config################# $geoData=Import-Csv $geoIPcvsPath -header sIP, eIP, start, end, cc, cn | where-object {$_.cc –eq $countryCode}$geoDataTotal=$geoData.Count$remoteIP="" ###### 룰이 있는 지 체크 ########function ruleExistsChk ($ruleName){ $fw=New-object -comObject HNetCfg.FwPolicy2; # http://blogs.technet.com/b/jamesone/archive/2009/02/18/how-to-manage-the-windows-firewall-settings-with-powershell.aspx $RuleCHK=$fw.rules | where-object {$_.name –eq $ruleName} if(!$RuleCHK){ #$deny_rule_name + " 룰이 생성되어 있지 않습니다."; exit; netsh advfirewall firewall add rule name="$ruleName" localip=any dir=in action=block profile="any" interfacetype="any" }}###### 룰이 있는 지 체크 ######## $count=1foreach ($geoIP in $geoData){ #$remoteIP+=@($geoIP.sIP+"-"+$geoIP.eIP+",") #배열로 저장. $remoteIP+=$geoIP.sIP+"-"+$geoIP.eIP+"," #remoteAddr가 한개의 룰에 약 300개 이상이면 등록이 안됨. 안전하게 200으로 설정. if(($count%200) -eq 0) { $makeRuleName=$ruleName+$countryCode+$count ruleExistsChk($makeRuleName) netsh advfirewall firewall set rule name=$makeRuleName new remoteip="$remoteIP" $remoteIP="" }elseif($geoDataTotal -eq $count){ $makeRuleName=$ruleName+$countryCode+$count ruleExistsChk($makeRuleName) netsh advfirewall firewall set rule name=$makeRuleName new remoteip="$remoteIP" $remoteIP="" } $count++ } cs
실행은 파일에 마우스를 올린 후 우측버튼을 누른 후 "PowerShell에서 실행" 을 클릭하면 됩니다.
참고 URL : http://blog.netchk.net/?p=1427
제 블로그의 내용이 도움이 되셨나요?
▼▼▼▼▼▼▼▼▼▼▼
여러분의 공감과 댓글이 큰 힘이됩니다 :)
한국을 제외한 모든 국가를 차단할때는 어케하나요?
방어벽을 풀어도 적용되나요?
지금도 위에꺼로하면 차단되나요?