Click here to Skip to main content
15,890,690 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
i get only private ip and public ip address in but coludn't find port number please help me on this.

What I have tried:

string hostName = Dns.GetHostName(); // Retrive the Name of HOST
Console.WriteLine(hostName);
// Get the IP
string myIP = Dns.GetHostByName(hostName).AddressList[0].ToString();
Console.WriteLine("My IP Address is :"+myIP);
Console.ReadKey();
Posted
Updated 25-Jul-19 16:56pm

Thanks @Richard Deeming i get the my listtening port is it possible to set my own port number using c# code.
 
Share this answer
 
Comments
Dave Kreskowiak 25-Jul-19 23:32pm    
You posted this as a SOLUTION to your own question, not as a reply to Richard. He has no idea you tried to reply to him because of this.

See the "Have a Question or Comment" button under his solution? Click that and you can reply to him.
Murali10111 25-Jul-19 23:52pm    
Is it possible to set my own port number using c# code?
You can read the configured port number from the registry:
C#
using (Microsoft.Win32.RegistryKey key = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(@"System\CurrentControlSet\Control\Terminal Server\WinStations\RDP-Tcp", false))
{
    if (key is null)
    {
        Console.WriteLine("RDP is not enabled.");
    }
    else
    {
        int port = (int)key.GetValue("PortNumber", 3389);
        Console.WriteLine("RDP port: {0}", port);
    }
}

Change the listening port in Remote Desktop | Microsoft Docs[^]
 
Share this answer
 
Quote:
I need to get rdp port number in C#?

The RDP (Remote Desktop Protocol) port number is always 3389.

Quote:
i get only private ip and public ip address in but coludn't find port number please help me on this.

You can't "find" a port number like you find your private and public IP. While you have a public IP and have a private IP, you don't have a port. When you connect to a remote machine you can use whatever port the machine has opened for you.
 
Share this answer
 
Comments
Richard Deeming 25-Jul-19 8:29am    
"The RDP (Remote Desktop Protocol) port number is always 3389."

Are you sure about that? :)
Change the listening port in Remote Desktop | Microsoft Docs[^]
Thomas Daniels 25-Jul-19 8:35am    
Hmm, not, then :)
5 to your answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900