Post Details

How can I verify that NSG rules allow ports 22 (SSH) and 3389 (RDP) from 168.63.129.16 in D365FO using X++?

You can use the following X++ code to verify that NSG rules allow ports 22 (SSH) and 3389 (RDP) from 168.63.129.16 in D365FO: ``` public static void verifyNSGRules() { str securityGroupId = "YourSecurityGroupIdHere"; str ipAddress = "168.63.129.16"; str[] allowedPorts = ['22', '3389']; AzureNSGServiceClient client = AzureNSGServiceClient::construct(); AzureNSGRuleList rules = client.getNSGRules(securityGroupId); boolean sshAllowed = false; boolean rdpAllowed = false; for (AzureNSGRule rule : rules) { if (rule.getAccess().toString() == 'Allow' && rule.getDirection().toString() == 'Inbound') { if (strCmp(rule.getProtocol().toString(), 'TCP') == 0 && strFind(rule.getDestinationPortRange(), allowedPorts[0]) != 0) { sshAllowed = true; } else if (strCmp(rule.getProtocol().toString(), 'TCP') == 0 && strFind(rule.getDestinationPortRange(), allowedPorts[1]) != 0) { rdpAllowed = true; } } } if (sshAllowed && rdpAllowed) { info(strFmt("NSG rules allow ports 22 (SSH) and 3389 (RDP) from IP address %1", ipAddress)); } else { info(strFmt("NSG rules do not allow ports 22 (SSH) and 3389 (RDP) from IP address %1", ipAddress)); } } ``` Make sure to replace "YourSecurityGroupIdHere" with the actual security group ID in your Azure environment. This code assumes you have a custom Azure NSG service client class defined with methods to retrieve NSG rules. You may need to adjust this code based on your specific Azure setup.




Leave A Reply


Name*

E-mail*