📅  最后修改于: 2022-03-11 14:50:21.791000             🧑  作者: Mango
# Retrieve current IP address
$IP=Invoke-WebRequest -UseBasicParsing http://whatismyip.akamai.com/
$sg="sg-00001"
$old_file_path = 'old_ip.txt'
if(Test-Path -Path $old_file_path){
$OldIp=Get-Content -Path $old_file_path
aws ec2 revoke-security-group-ingress --group-id "$sg" --protocol tcp --port 8443 --cidr "$OldIp/32"
}
aws ec2 authorize-security-group-ingress --group-id "$sg" --protocol tcp --port 8443 --cidr "$IP/32"
Set-Content -Path $old_file_path -Value $IP