[英]How to get list of Endpoint Statistics and Dangerous Endpoints by using of Azure Mgmt SDK fluent
I am using https://www.nuget.org/packages/Microsoft.Azure.Management.Fluent for getting resources in Azure with programmatically(C#.NET-Core Web app) and tried to get resources information by providing service principals(CS) as below... I am using https://www.nuget.org/packages/Microsoft.Azure.Management.Fluent for getting resources in Azure with programmatically(C#.NET-Core Web app) and tried to get resources information by providing service principals(CS ) 如下...
string subscriptionId = "xxx";
string clientId = "xxx";
string tenantId = "xxx";
string clientSecret = "xxx";
AzureCredentials cred = new AzureCredentialsFactory()
.FromServicePrincipal(
clientId,
clientSecret,
tenantId,
AzureEnvironment.AzureGlobalCloud
);
var azure = Azure.Configure()
.WithLogLevel(HttpLoggingDelegatingHandler.Level.Basic)
.Authenticate(cred)
.WithSubscription(subscriptionId);
Any sample code(C#.NET-Core Web app) to find out Endpoint Statistics ( loop through open ports in NSG and list them in details) and Dangerous Endpoints (loop through open ports in NSG and identify ports like 3389/22).任何示例代码(C#.NET-Core Web 应用程序),以找出端点统计信息(循环通过 NSG 中的开放端口并详细列出它们)和危险端点(循环通过 NSG 中的开放端口并识别端口,如 3389/22)。
Pls, advice on above.请在上面提供建议。
Thanks谢谢
If you mean list all the ports in NSG -> Inbound security rules, like screenshot below:如果您的意思是列出 NSG 中的所有端口 -> 入站安全规则,如下图所示:
Then you can use the code like below:然后你可以使用如下代码:
foreach (var nsg in azure.NetworkSecurityGroups.List())
{
var rules = nsg.SecurityRules;
foreach (var r in rules)
{
Console.WriteLine($"*** the NSG: {r.Value.Name} ***");
if (r.Value.DestinationPortRange != null)
{
//after you get the port, you can apply your logic here.
Console.WriteLine(r.Value.DestinationPortRange);
}
if (r.Value.DestinationPortRanges != null)
{
foreach (var port in r.Value.DestinationPortRanges)
{
//after you get the port, you can apply your logic here.
Console.WriteLine(port);
}
}
Console.WriteLine("**end**");
}
}
Thanks @ivan Yang,, for response and help...感谢@ivan Yang,您的回复和帮助...
Below is working code, i modified urs code as per my下面是工作代码,我根据我的修改了 urs 代码
var ntwrrkDetails = new List<EndTcpPorts>();
EndTcpPorts objEndTcpPorts; // cls object
foreach (var nsg in azure.NetworkSecurityGroups.List())
{
objEndTcpPorts = new EndTcpPorts();
objEndTcpPorts.ResourceGroup = nsg.ResourceGroupName.ToString();
try
{
var rules = nsg.SecurityRules;
foreach (var r in rules)
{
try
{
objEndTcpPorts.NSGName = r.Value.Name.ToString();
}
catch (Exception)
{
objEndTcpPorts.NSGName = "";
}
if (r.Value.DestinationPortRanges != null)
{
try
{
//get ports
objEndTcpPorts.TcpPorts = r.Value.DestinationPortRange.ToString(); //((Microsoft.Azure.Management.ResourceManager.Fluent.Core.IndexableWrapper<Microsoft.Azure.Management.Network.Fluent.Models.SecurityRuleInner>)r.Value).Inner.Protocol.Value.ToString();
}
catch (Exception)
{
objEndTcpPorts.TcpPorts = "";
}
}
}
}
catch (Exception)
{
continue;
}
ntwrrkDetails.Add(objEndTcpPorts); // add to list
}
Now we can check(Dangerous Endpoints) in tcp ports as open ports in NSG and identify ports like 3389/22 or *..现在我们可以将 tcp 端口中的(危险端点)检查为 NSG 中的开放端口,并识别 3389/22 或 *..
Many Thanks,非常感谢,
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.