BogaNet 1.4.0
Loading...
Searching...
No Matches
Static Public Member Functions | List of all members
BogaNet.Helper.NetworkHelper Class Referenceabstract

Various helper functions for networking. More...

Static Public Member Functions

static ? IWebProxy SetGlobalProxyToDefault ()
 Sets the global proxy for all network requests to the default.
 
static IWebProxy SetGlobalProxy (string user, string password, string url)
 Sets the global proxy for all network requests with the given credentials.
 
static bool OpenURL (string? url)
 Opens the given URL with the file explorer or browser.
 
static bool RemoteCertificateValidationCallback (object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
 HTTPS-certification callback, which overrides the checks for invalid certificates (like dev-certs). NOTE: do not use this in production since it breaks the SSL security!
 
static string GetURLForFile (string path)
 Returns the URL of a given file.
 
static string ValidateURL (string url, bool removeProtocol=false, bool removeWWW=true, bool removeSlash=true)
 Validates a given URL.
 
static bool IsURL (string? url)
 Checks if the input is an URL.
 
static bool IsIPv4 (string? ip)
 Checks if the input is an IPv4 address.
 
static bool IsIPv6 (string? ip)
 Checks if the input is an IPv6 address.
 
static string GetIP (string host)
 Returns the IP of a given host name.
 
static string GetPublicIP (string checkUrl="https://checkip.amazonaws.com/")
 Returns the public IP of the Internet connection.
 
static async Task< string > GetPublicIPAsync (string checkUrl="https://checkip.amazonaws.com/")
 Returns the public IP of the Internet connection asynchronously.
 
static List< NetworkAdapterGetNetworkAdapters (bool activeOnly=true)
 Returns a list of all available network interfaces.
 
static bool CheckInternetAvailability ()
 Checks the availability of the Internet (aka "Captive Portal Detection").
 
static async Task< bool > CheckInternetAvailabilityAsync ()
 Checks the availability of the Internet (aka "Captive Portal Detection") asynchronously.
 
static long Ping (string hostname)
 Pings a given host and returns the Roundtrip-Time.
 
static async Task< long > PingAsync (string hostname)
 Pings a given host and returns the Roundtrip-Time asynchronously.
 
static string ReadAllText (string url)
 Reads the text of a file from a given URL.
 
static async Task< string > ReadAllTextAsync (string url)
 Reads the text of a file from a given URL asynchronously.
 
static string[] ReadAllLines (string url)
 Reads all lines of text from a file from a given URL.
 
static async Task< string[]> ReadAllLinesAsync (string url)
 Reads all lines of text from a file from a given URL asynchronously.
 
static byte[] ReadAllBytes (string url)
 Reads the bytes of a file from a given URL.
 
static async Task< byte[]> ReadAllBytesAsync (string url)
 Reads the bytes of a file from a given URL asynchronously.
 

Detailed Description

Various helper functions for networking.

Member Function Documentation

◆ CheckInternetAvailability()

static bool BogaNet.Helper.NetworkHelper.CheckInternetAvailability ( )
static

Checks the availability of the Internet (aka "Captive Portal Detection").

Returns
True if a connection to the Internet is available

◆ CheckInternetAvailabilityAsync()

static async Task< bool > BogaNet.Helper.NetworkHelper.CheckInternetAvailabilityAsync ( )
static

Checks the availability of the Internet (aka "Captive Portal Detection") asynchronously.

Returns
True if a connection to the Internet is available

◆ GetIP()

static string BogaNet.Helper.NetworkHelper.GetIP ( string host)
static

Returns the IP of a given host name.

Parameters
hostHost name
Returns
IP of a given host name
Exceptions
Exception

◆ GetNetworkAdapters()

static List< NetworkAdapter > BogaNet.Helper.NetworkHelper.GetNetworkAdapters ( bool activeOnly = true)
static

Returns a list of all available network interfaces.

Parameters
activeOnlySearch only for active network interfaces (optional, default: true)
Returns
List of network interfaces.

◆ GetPublicIP()

static string BogaNet.Helper.NetworkHelper.GetPublicIP ( string checkUrl = "https://checkip.amazonaws.com/")
static

Returns the public IP of the Internet connection.

Parameters
checkUrlExternal url to check the ip (optional, default: https://checkip.amazonaws.com/
Returns
Public IP of the Internet connection.

◆ GetPublicIPAsync()

static async Task< string > BogaNet.Helper.NetworkHelper.GetPublicIPAsync ( string checkUrl = "https://checkip.amazonaws.com/")
static

Returns the public IP of the Internet connection asynchronously.

Parameters
checkUrlExternal url to check the ip (optional, default: https://checkip.amazonaws.com/
Returns
Public IP of the Internet connection.

◆ GetURLForFile()

static string BogaNet.Helper.NetworkHelper.GetURLForFile ( string path)
static

Returns the URL of a given file.

Parameters
pathFile path
Returns
URL of the file path

◆ IsIPv4()

static bool BogaNet.Helper.NetworkHelper.IsIPv4 ( string? ip)
static

Checks if the input is an IPv4 address.

Parameters
ipInput as possible IPv4
Returns
True if the given input is an IPv4 address

◆ IsIPv6()

static bool BogaNet.Helper.NetworkHelper.IsIPv6 ( string? ip)
static

Checks if the input is an IPv6 address.

Parameters
ipInput as possible IPv6
Returns
True if the given input is an IPv6 address

◆ IsURL()

static bool BogaNet.Helper.NetworkHelper.IsURL ( string? url)
static

Checks if the input is an URL.

Parameters
urlInput as possible URL
Returns
True if the given path is an URL

◆ OpenURL()

static bool BogaNet.Helper.NetworkHelper.OpenURL ( string? url)
static

Opens the given URL with the file explorer or browser.

Parameters
urlURL to open
Returns
True if the operation was successful
Exceptions
Exception

◆ Ping()

static long BogaNet.Helper.NetworkHelper.Ping ( string hostname)
static

Pings a given host and returns the Roundtrip-Time.

Parameters
hostnameHost/IP to ping
Returns
Roundtrip-Time in milliseconds
Exceptions
Exception

◆ PingAsync()

static async Task< long > BogaNet.Helper.NetworkHelper.PingAsync ( string hostname)
static

Pings a given host and returns the Roundtrip-Time asynchronously.

Parameters
hostnameHost/IP to ping
Returns
Roundtrip-Time in milliseconds
Exceptions
Exception

◆ ReadAllBytes()

static byte[] BogaNet.Helper.NetworkHelper.ReadAllBytes ( string url)
static

Reads the bytes of a file from a given URL.

Parameters
urlURL to the file
Returns
Byte-content of the file
Exceptions
Exception

◆ ReadAllBytesAsync()

static async Task< byte[]> BogaNet.Helper.NetworkHelper.ReadAllBytesAsync ( string url)
static

Reads the bytes of a file from a given URL asynchronously.

Parameters
urlURL to the file
Returns
Byte-content of the file
Exceptions
Exception

◆ ReadAllLines()

static string[] BogaNet.Helper.NetworkHelper.ReadAllLines ( string url)
static

Reads all lines of text from a file from a given URL.

Parameters
urlURL to the file
Returns
Array of text lines from the file
Exceptions
Exception

◆ ReadAllLinesAsync()

static async Task< string[]> BogaNet.Helper.NetworkHelper.ReadAllLinesAsync ( string url)
static

Reads all lines of text from a file from a given URL asynchronously.

Parameters
urlURL to the file
Returns
Array of text lines from the file
Exceptions
Exception

◆ ReadAllText()

static string BogaNet.Helper.NetworkHelper.ReadAllText ( string url)
static

Reads the text of a file from a given URL.

Parameters
urlURL to the file
Returns
Text-content of the file
Exceptions
Exception

◆ ReadAllTextAsync()

static async Task< string > BogaNet.Helper.NetworkHelper.ReadAllTextAsync ( string url)
static

Reads the text of a file from a given URL asynchronously.

Parameters
urlURL to the file
Returns
Text-content of the file
Exceptions
Exception

◆ RemoteCertificateValidationCallback()

static bool BogaNet.Helper.NetworkHelper.RemoteCertificateValidationCallback ( object sender,
X509Certificate certificate,
X509Chain chain,
SslPolicyErrors sslPolicyErrors )
static

HTTPS-certification callback, which overrides the checks for invalid certificates (like dev-certs). NOTE: do not use this in production since it breaks the SSL security!

Parameters
senderSender of the callback
certificateCertificate to check
chainChain to use
sslPolicyErrorsSSL errors
Returns
True if the validation of the certificate was successful

◆ SetGlobalProxy()

static IWebProxy BogaNet.Helper.NetworkHelper.SetGlobalProxy ( string user,
string password,
string url )
static

Sets the global proxy for all network requests with the given credentials.

Parameters
userUser for the proxy
passwordPassword for the proxy
urlUrl of the proxy
Returns
Used global proxy

◆ SetGlobalProxyToDefault()

static ? IWebProxy BogaNet.Helper.NetworkHelper.SetGlobalProxyToDefault ( )
static

Sets the global proxy for all network requests to the default.

Returns
Used global proxy

◆ ValidateURL()

static string BogaNet.Helper.NetworkHelper.ValidateURL ( string url,
bool removeProtocol = false,
bool removeWWW = true,
bool removeSlash = true )
static

Validates a given URL.

Parameters
urlURL to validate
removeProtocolRemove the protocol, e.g. http:// (optional, default: false)
removeWWWRemove www (optional, default: true)
removeSlashRemove slash at the end (optional, default: true)
Returns
Validated URL
Exceptions
ArgumentNullException

The documentation for this class was generated from the following file: