public string SetBlock(string ip, string note)
{
Process process = new Process();
process.StartInfo.FileName = "netsh.exe";
process.StartInfo.RedirectStandardOutput = true;
process.StartInfo.RedirectStandardInput = true;
process.StartInfo.RedirectStandardError = true;
process.StartInfo.UseShellExecute = false;
process.StartInfo.CreateNoWindow = true;
process.Start();
process.StandardInput.WriteLine(string.Concat(new string[]
{
" ipsec static add filter filterlist =BlockIPList srcaddr=",
ip,
" description=",
note,
" dstaddr=Me protocol=tcp srcport=0 dstport=80"
}));
process.StandardInput.WriteLine("exit");
string text = process.StandardOutput.ReadToEnd();
process.Close();
return text.Replace("\r\n", "");
}
通過安全策略BlockIPList創建對應的篩選器,限制訪問服務器IP
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.