
In this article, I'll guide you in turning off the ping to your machine and changing the default Remote Desktop (RDP) listening port 3389.
If your computer has the IPv6 protocol enabled, your IP is available for web connections without any configurations at your modem. In IPv6, the address is routed from router to router until it reaches your device.
Modems usually inactivate this behavior, but you must be careful if you want to access your Windows device via RDP.
Turning off the ICPM protocol
First, turn off the ping echo so your device will not be easily discovered online.
To do this, open your Power Shell command as administrator and run the code below.

Starting Power Shell as Administrator
Code to block ping, ICPM protocol.
# Define the new firewall rule
$ruleName = "Block ICMP Echo Requests"
$ruleDescription = "This rule blocks ICMP echo requests to disallow ping."
# Check if the rule already exists
$existingRule = Get-NetFirewallRule -DisplayName $ruleName -ErrorAction SilentlyContinue
if ($existingRule) {
Write-Host "The rule '$ruleName' already exists. Deleting the existing rule..."
Remove-NetFirewallRule -DisplayName $ruleName
}
# Create a new rule to block ICMP echo requests
New-NetFirewallRule -DisplayName $ruleName `
-Description $ruleDescription `
-Protocol ICMPv4 `
-IcmpType 8 `
-Direction Inbound `
-Action Block
Write-Host "The rule '$ruleName' has been created successfully and ICMP echo requests are now blocked."
Code to remove protocol ICMP.
You need to restart your device to take effect!
Changing RDP Port using a .NET Console app
Create a console app to change the RDP Port. Open a command line and follow these commands.
md RdpCommandPortChanger
cd RdpCommandPortChanger
dotnet new console
Note. To do this, you must install .NET and Visual Studio, or VS Code, on your machine. You can download it at https://dotnet.microsoft.com/en-us/download/dotnet.
Enter the RdpCommandPortChanger.csproj using Visual Studio and add this code to the Program.cs file.
// Define the registry path
using Microsoft.Win32;
var registryPath = @"SYSTEM\CurrentControlSet\Control\Terminal Server\WinStations\RDP-Tcp";
var valueName = "PortNumber";
// Open the registry key
using var key = Registry.LocalMachine.OpenSubKey(registryPath);
if (key != null)
{
// Read the port number
var portNumberValue = key.GetValue(valueName);
if (portNumberValue != null)
{
// Convert the port number to an integer
int portNumber = (int)portNumberValue;
// Print the port number to the console
Console.WriteLine($"Current Port Number for RDP: {portNumber}");
// Read new port number from the console
Console.Write("Enter new port number: ");
if (int.TryParse(Console.ReadLine(), out int newPortNumber))
{
// Open the registry key with write access
using var keyX = Registry.LocalMachine.OpenSubKey(registryPath, writable: true);
if (keyX != null)
{
// Update the port number in the registry
keyX.SetValue(valueName, newPortNumber, RegistryValueKind.DWord);
Console.WriteLine($"Port number updated to: {newPortNumber}");
}
else
{
Console.WriteLine("Registry key not found.");
}
}
else
{
Console.WriteLine("Invalid port number.");
}
}
else
{
Console.WriteLine("Port number not found.");
}
}
else
{
Console.WriteLine("Registry key not found.");
}
Console.WriteLine("Press ENTER to exit!");
Console.ReadKey();




Join the conversation! Your thoughts help the community grow.