Skip to content

Instantly share code, notes, and snippets.

@zatarra
Last active October 18, 2019 14:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zatarra/5491278 to your computer and use it in GitHub Desktop.
Save zatarra/5491278 to your computer and use it in GitHub Desktop.
Simple DynDns Updater Class written in VB.NET
' .Net DynDNS client class by David Gouveia - me[_@_]davidgouveia.net
' Feel free to use it as long as you don't remove the credits :o)
Imports System.Net
Imports System.IO
Public Class DynDnsUpdater
Private _username, _password, _host, _ip As String
Public Enum UpdateStatus
SUCESS
FAIL
NOCHANGE
End Enum
Private Function checkip() As String
Dim ipRegex As New System.Text.RegularExpressions.Regex("[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}", System.Text.RegularExpressions.RegexOptions.Singleline)
Try
Dim UpdateClient As System.Net.HttpWebRequest = WebRequest.Create( _
New Uri("http://checkip.dyndns.org"))
UpdateClient.Timeout = 15000
Dim response As WebResponse = UpdateClient.GetResponse()
Dim content As Stream = response.GetResponseStream()
Dim readstream As New StreamReader(content, System.Text.Encoding.Default)
Dim IpAddress As String = readstream.ReadToEnd
readstream.Close()
content.Close()
If ipRegex.IsMatch(IpAddress) Then
Return ipRegex.Match(IpAddress).Groups(0).Value
Else
Return Nothing
End If
Catch
Return Nothing
End Try
End Function
Public Sub New(ByVal username As String, ByVal password As String, ByVal host As String)
_username = username
_password = password
_host = host
End Sub
Public Function update() As UpdateStatus
_ip = checkip()
Dim UpdateClient As System.Net.HttpWebRequest = WebRequest.Create( _
New Uri("http://members.dyndns.org/nic/update?hostname=" + _host + "&myip=" + _ip))
UpdateClient.Credentials = New NetworkCredential(_username, _password)
UpdateClient.PreAuthenticate = True
UpdateClient.UserAgent = ".Net DynDNS Updater Client"
UpdateClient.Timeout = 15000
Dim response As WebResponse = UpdateClient.GetResponse()
Dim content As Stream = response.GetResponseStream()
Dim readstream As New StreamReader(content, System.Text.Encoding.Default)
Dim DynDnsResponse As String = readstream.ReadToEnd
readstream.Close()
content.Close()
If DynDnsResponse.Contains("good " + _ip) Then
Return UpdateStatus.SUCESS
ElseIf DynDnsResponse.Contains("nochg " + _ip) Then
Return UpdateStatus.NOCHANGE
Else
Return UpdateStatus.FAIL
End If
End Function
End Class
@alger1962
Copy link

Hi dear friend , Is this code work well ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment