4

I am trying to access EC2 machines remotely to get some info using C#. I wrote code as below:-

ConnectionOptions options = new ConnectionOptions
{
Username = serverspace.ServerIP + @"\xxxxxx",
Password = "xxxxxxx",
Impersonation = ImpersonationLevel.Impersonate,
EnablePrivileges = true
};

ManagementScope scope = new ManagementScope(String.Format(@"\\{0}\ROOT\CIMV2", serverspace.ServerIP), options);

scope.Connect();

But an RPC exception is thrown as below:- The RPC server is unavailable. (Exception from HRESULT: 0x800706BA) at System.Runtime.InteropServices.Marshal.ThrowExceptionForHRInternal(Int32 errorCode, IntPtr errorInfo) at System.Management.ManagementScope.InitializeGuts(Object o) at System.Management.ManagementScope.Initialize()

1- Is the problem in the code? 2- Do I need to adjust anything in all machines firewall?

Bassam Gamal
  • 250
  • 4
  • 12

1 Answers1

2

RPC firewall ports are documented here:

Service overview and network port requirements for Windows
-Remote Procedure Call (RPC):
http://support.microsoft.com/kb/832017#method39

System service name: RpcSs  
Application protocol    Protocol    Ports  
RPC TCP 135  
RPC over HTTPS  TCP 593  
NetBIOS Datagram Service    UDP 138  
NetBIOS Name Resolution UDP 137  
NetBIOS Session Service TCP 139  
SMB TCP 445  

Additionally, you need the "high ports" range 49152 through 65535.

Greg Askew
  • 35,880
  • 5
  • 54
  • 82
  • So this is thing to adjust for all EC2 instances' firewall or I've to adjust it from Security Group? – Bassam Gamal Apr 23 '13 at 14:22
  • I'm not sure what you mean. RPC and WMI require a truckload of ports to be open in the firewall. If you don't have the firewalls configured appropriately, WMI is not a viable option. – Greg Askew Apr 23 '13 at 14:29