-
-
Notifications
You must be signed in to change notification settings - Fork 6
Port
The PortExtension
class provides extension methods to help with port operations.
public static class PortExtension
Gets the name of the service listening on the specified Port
.
-
Port
(int) (Optional) - The port number for which the service name is required. Default value isMPPM.Port
.
A string that contains the name of the service, if found; otherwise, the string "Unknown
".
-
Exception
- An error occurred while retrieving the service name.
int port = 80;
string service = port.Info();
Console.WriteLine(service); // Output: "HTTP"
Asynchronously gets the name of the service listening on the specified Port
.
-
Port
(int) (Optional) - The port number for which the service name is required. Default value isMPPM.Port
.
A task that represents the asynchronous operation. The task result contains a string that contains the name of the service, if found; otherwise, the string "Unknown
".
-
Exception
- An error occurred while retrieving the service name.
int port = 80;
string service = await port.InfoAsync();
Console.WriteLine(service); // Output: "HTTP"
Gets the names of the services listening on the specified ports.
-
Ports
(int[]) (Optional) - An array of port numbers for which the service names are required. Default value isMPPM.Ports
.
A dictionary that contains the names of the services, indexed by their respective port numbers. If a service is not found on a port, the value of the corresponding key is "Unknown
".
-
Exception
- An error occurred while retrieving the service names.
int[] ports = {80, 443};
Dictionary<int, string> services = ports.Info();
foreach (var item in services)
{
Console.WriteLine("{0}: {1}", item.Key, item.Value);
}
// Output:
// 80: HTTP
// 443: HTTPS
Asynchronously gets the names of the services listening on the specified ports.
-
Ports
(int[]) (Optional) - An array of port numbers for which the service names are required. Default value isMPPM.Ports
.
A task that represents the asynchronous operation. The task result contains a dictionary that contains the names of the services, indexed by their respective port numbers. If a service is not found on a port, the value of the corresponding key is "Unknown
".
-
Exception
- An error occurred while retrieving the service names.
int[] ports = {80, 443};
Dictionary<int, string> services = await ports.InfoAsync();
foreach (var item in services)
{
Console.WriteLine("{0}: {1}", item.Key, item.Value);
}
// Output:
// 80: HTTP
// 443: HTTPS
Namespace: Skylark.Standard.Extension.Port
Assembly: Skylark.Standard.dll
Package: Skylark.Standard
This class provides extension methods for port-related operations.
- System.Object
Gets information about a specified port.
Syntax
public static string Info(int Port = MPPM.Port);
Parameters
Port
(optional)
The port number to get information about. Defaults toMPPM.Port
.
Returns
- A object that contains information about the specified port.
The following example demonstrates how to use the Info
method to get information about a port.
string result = PortExtension.Info(80);
Asynchronously gets information about a specified port.
Syntax
public static Task<string> InfoAsync(int Port = MPPM.Port);
Parameters
Port
(optional)
The port number to get information about. Defaults toMPPM.Port
.
Returns
- A object representing the asynchronous operation that returns a object that contains information about the specified port.
The following example demonstrates how to use the InfoAsync
method to get information about a port asynchronously.
Task<string> task = PortExtension.InfoAsync(80);
string result = await task;
Gets information about an array of ports.
Syntax
public static Dictionary<int, string> Info(int[] Ports = null);
Parameters
Ports
(optional)
An array of port numbers to get information about. Defaults toMPPM.Ports
.
Returns
- A object that contains the key-value pairs representing the properties and their values of the specified object.
Retrieves information about network ports.
-
Ports: An integer array of port numbers. Optional parameter with default value of
null
.
A Task<Dictionary<int, string>>
object that represents the asynchronous operation. The dictionary contains port numbers as keys and their corresponding information as values.
Scans a single port on a remote host to check if it is open or closed.
-
Address: A string representing the IP address of the remote host. Optional parameter with default value of
PortManage.Address
. -
Port: An integer representing the port number to scan. Optional parameter with default value of
PortManage.Port
. -
Timeout: An integer representing the timeout value in milliseconds. Optional parameter with default value of
PortManage.Timeout
.
A PortType
enum value that represents the status of the scanned port (PortType.Open
for open and PortType.Close
for closed).
Scans a single port on a remote host to check if it is open or closed asynchronously.
-
Address: A string representing the IP address of the remote host. Optional parameter with default value of
PortManage.Address
. -
Port: An integer representing the port number to scan. Optional parameter with default value of
PortManage.Port
. -
Timeout: An integer representing the timeout value in milliseconds. Optional parameter with default value of
PortManage.Timeout
.
A Task<PortType>
object that represents the asynchronous operation. The PortType
enum value represents the status of the scanned port (PortType.Open
for open and PortType.Close
for closed).
Scans multiple ports on a remote host to check if they are open or closed.
-
Address: A string representing the IP address of the remote host. Optional parameter with default value of
PortManage.Address
. -
Ports: An integer array representing the port numbers to scan. Optional parameter with default value of
null
, which means all ports defined inPortManage.Ports
will be scanned. -
Timeout: An integer representing the timeout in milliseconds. Optional parameter with default value of
PortManage.Timeout
.
The Scan
method returns a value of type PortType
which indicates whether the specified port is open or closed. The ScanMultiple
method returns a Dictionary
with keys representing the port numbers and values representing the port types.
The InfoAsync
and ScanAsync
methods are asynchronous versions of the Info
and Scan
methods, respectively. They return Task
objects that can be awaited.
Example usage:
Dictionary<int, PortType> result = PortExtension.ScanMultiple("127.0.0.1", new int[] { 80, 443, 8080 });
foreach (KeyValuePair<int, PortType> pair in result)
{
Console.WriteLine("Port {0}: {1}", pair.Key, pair.Value);
}
This code scans ports 80, 443, and 8080 on the local machine and prints the results.
- Tax
- Url
- Web
- Ping
- Port
- Text
- Time
- Hash
- Word
- Color
- Speed
- Lottery
- Storage
- Browser
- Unicode
- Password
- JavaScript
- Cryptology
- Typography
- Temperature
- Compression
- Decompression
- Cascading Style Sheets
- JavaScript Object Notation
- Hypertext Markup Language
- Extensible Markup Language
- Extensible HyperText Markup Language