public sealed class UtilHosts
Public NotInheritable Class UtilHosts
Dim instance As UtilHosts
public ref class UtilHosts sealed
[<SealedAttribute>]
type UtilHosts = class end
No code example is currently available or this language may not be supported.
No code example is currently available or this language may not be supported.
' Set a new mapping.
Dim mapping As New HostsMappingInfo
With mapping
.HostName = "cuantodanio.es"
.Ip = "127.0.0.1"
.Comment = "Test mapping comment."
End With
' Delete the Host file.
If HostsUtil.FileExists Then
HostsUtil.FileDelete()
End If
' Create a new one Hosts file.
HostsUtil.FileCreate(overwrite:=True)
' Add some new mappings.
HostsUtil.Add(mapping)
HostsUtil.Add(enabled:=True, hostName:="www.youtube.com", ip:="127.0.0.1", comment:="Test mapping comment")
' Check whether a mapping exists.
If HostsUtil.IsMapped(mapping) Then
' Disable the mapping.
HostsUtil.Disable(mapping)
End If
' Check whether an existing mapping is disabled.
If HostsUtil.IsDisabled("www.youtube.com") Then
' Remove the mapping.
HostsUtil.Remove("www.youtube.com")
End If
' Get the IP of a mapped Hostname.
MessageBox.Show("cuantodanio.es: " & HostsUtil.GetMappingFromHostname("cuantodanio.es").Ip)
' Get all the hostname mappings
Dim mappings As List(Of HostsMappingInfo) = HostsUtil.Mappings()
For Each mappingInfo As HostsMappingInfo In mappings
Dim sb As New Global.System.Text.StringBuilder
With sb
.AppendLine(String.Format("Hostname...: {0}", mappingInfo.HostName))
.AppendLine(String.Format("IP Address.: {0}", mappingInfo.Ip))
.AppendLine(String.Format("Comment....: {0}", mappingInfo.Comment))
.AppendLine(String.Format("Is Enabled?: {0}", Not mappingInfo.IsDisabled))
End With
MessageBox.Show(sb.ToString(), "HostsFile Mappings", MessageBoxButtons.OK, MessageBoxIcon.Information)
Next mappingInfo
' Get all the hostname mappings that matches an ip address
Dim mappingMatches As List(Of HostsMappingInfo) = HostsUtil.GetMappingsFromIP("127.0.0.1")
No code example is currently available or this language may not be supported.
No code example is currently available or this language may not be supported.
No code example is currently available or this language may not be supported.
No code example is currently available or this language may not be supported.
Add(HostsMappingInfo) | Adds a new mapping. |
Add(Boolean, String, String, String) | Adds a new mapping in the Hosts file. |
Disable(HostsMappingInfo) | Disables an existing mapping. |
Disable(String) | Disables an existing mapping. |
Equals | Determines whether the specified object is equal to the current object. (Inherited from Object) |
FileClear | Clears all the mappings in the Hosts file. |
FileCreate | Creates the Hosts file. |
FileDelete | Deletes the Hosts file. |
FileExists | Checks whether the Hosts file exists. |
GetHashCode | Serves as the default hash function. (Inherited from Object) |
GetMappingFromHostname | Gets a HostsMappingInfo instance containing the mapping info of a hostname. |
GetMappingsFromIP | Gets a ListT instance containing the mapping info of all mappings matching the specified IP address. |
GetType | Gets the Type of the current instance. (Inherited from Object) |
IsDisabled(HostsMappingInfo) | Checks whether a HostName is already disabled. |
IsDisabled(String) | Checks whether a HostName is already disabled. |
IsMapped(HostsMappingInfo) | Checks whether a HostName is already mapped. |
IsMapped(String) | Checks whether a HostName is already mapped. |
Remove(HostsMappingInfo) | Removes a mapping. |
Remove(String) | Removes a mapping. |
ToString | Returns a string that represents the current object. (Inherited from Object) |
CanConvertTo |
Determines whether the source object can be converted to the specified target type.
(Defined by ObjectExtensions) |
CanConvertToT |
Determines whether the source object can be converted to the specified target type.
(Defined by ObjectExtensions) |
ConvertToT |
Converts an object to the specified target type.
If the conversion fails, an exception is thrown.
(Defined by ObjectExtensions) |
ConvertToT |
Converts an object to the specified target type.
If the conversion fails, returns the specified default value.
(Defined by ObjectExtensions) |
IsDisposable |
Determines whether the specified object is a disposable type
(i.e., it implements IDisposable interface).
(Defined by ObjectExtensions) |
Speak |
Speaks the string representation of the source object by using the
operating system integrated text-to-speech synthesizer.
(Defined by ObjectExtensions) |
Speak |
Speaks the string representation of the source object by using the
operating system integrated text-to-speech synthesizer.
(Defined by ObjectExtensions) |
ThrowIfNullTException |
Throws the specified exception if the source object is null.
(Defined by ObjectExtensions) |