Tell us what’s happening:
Describe your issue in detail here.
The developer helped me.
But I can’t put this together.
Because I’m a computer beginner.
How can I put them together?
They told me to look it up in another community, so I looked it up, but…
There wasn’t.
Your code so far
#############Config#################
$countryCode="CN", "RU", "KP" #차단할 나라의 CountryCode
#$geoIPcvsPath="d:\IP2LOCATION-LITE-DB1.CSV"
$geoIPcvsPath="\IP2LOCATION-LITE-DB1.CSV"
$ruleName="blockCountry"
#############Config#################
$geoData=Import-Csv $geoIPcvsPath -header sIP, eIP, start, end, cc, cn | where-object {$_.cc –in $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=1
foreach ($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++
}
# Helper function that converts a big-endian 32-bit value representing
# an IPv4 address into its string representation.
# E.g.:
# ConvertTo-Ipv4FromBigEndian 16779263 # -> '1.0.7.255'
function ConvertTo-Ipv4FromBigEndian {
param([uint32] $bigEndianIpv4)
$byteArray = [BitConverter]::GetBytes($bigEndianIpv4)
[Array]::Reverse($byteArray)
([IPAddress] [BitConverter]::ToUInt32($byteArray)).ToString()
}
# Note: Here I'm assuming that the input CSV file, IP2LOCATION-LITE-DB1.CSV,
# is located in the *current* directory; adjust as needed.
$geoData =
Import-Csv -Header start,end,cc,cn IP2LOCATION-LITE-DB1.CSV |
Select-Object @{ n='sIp'; e={ ConvertTo-Ipv4FromBigEndian $_.start } },
@{ n='eIp'; e={ ConvertTo-Ipv4FromBigEndian $_.end } },
*
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:101.0) Gecko/20100101 Firefox/101.0
Challenge: Hide Potentially Dangerous Information Using helmet.hidePoweredBy()
Link to the challenge: