简体   繁体   English

如何使用 Azure Mgmt SDK fluent 获取端点统计信息和危险端点列表

[英]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.

相关问题 如何使用 Azure Mgmt SDK fluent 获取所有快照 - How to get all snapshot by using of Azure Mgmt SDK fluent 如何使用 Azure Mgmt SDK fluent 获取空资源组列表 - How to get list of Empty Resource Groups by using of Azure Mgmt SDK fluent 如何使用 Azure Mgmt SDK fluent 获取 Active Directory 用户总数 - How to get total count of Active Directory users by using of Azure Mgmt SDK fluent How to get Azure Storage Account Key (connectionString) using azure .net sdk or fluent API? - How to get Azure Storage Account Key (connectionString) using azure .net sdk or fluent API? How to validate ARM Template using azure .net SDK or Fluent API? - How to validate ARM Template using azure .net SDK or Fluent API? 在 azure sdk fluent 中使用身份验证令牌 - Using authentication token in azure sdk fluent 如何使用 fluent Resource Manager SDK 获取部署的 outputResources? - How to get the outputResources of a deployment using the fluent Resource Manager SDK? 使用 azure .net SDK 或 Fluent ZDB974238714CA8DE64FZACE1D8037 - List all file share from storage account using azure .net SDK or Fluent API? 如何使用命名空间终结点获取带有死信消息的天蓝色队列列表? - How to get azure queue list with dead letter messages using namespace endpoint? 在Azure函数中使用Azure Fluent SDK时,如何使用托管服务标识创建azure对象? - When using the Azure Fluent SDK in an Azure Function how can I create an azure object using a Managed Service Identity?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM