No-IP UDF


SUBMITTED BY: Guest

DATE: May 28, 2013, 5:31 p.m.

FORMAT: Text only

SIZE: 8.5 kB

HITS: 998

  1. #include-once
  2. #AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7
  3. ; #INDEX# =======================================================================================================================
  4. ; Title .........: NoIP UDF v.1.0.0
  5. ; AutoIt Version : v3.3.8.1
  6. ; Description ...: NoIP API UDF
  7. ; Author(s) .....: Nessie
  8. ; ===============================================================================================================================
  9. ; #INCLUDES# =========================================================================================================
  10. ; None
  11. ; #GLOBAL VARIABLES# =================================================================================================
  12. ; None
  13. ; #CURRENT# =====================================================================================================================
  14. ; _NOIP_DNSUpdate
  15. ; _NOIP_HostnameResolve
  16. ; ===============================================================================================================================
  17. ; #INTERNAL_USE_ONLY# ===========================================================================================================
  18. ; __NOIP_GetIpAddress
  19. ; ===============================================================================================================================
  20. ; #FUNCTION# ====================================================================================================================
  21. ; Name ..........: _NOIP_DNSUpdate
  22. ; Description ...: Update multiple no-ip hostnames
  23. ; Syntax ........: _NOIP_DNSUpdate($sUser, $sPass, $sHostname[, $sIP = ""[, $bOffline = False[, $bSecure = True]]])
  24. ; Parameters ....: $sUser - Your no-ip username
  25. ; $sPass - Your no-ip password
  26. ; $sHostname - Your no-ip hostname.
  27. ; - If updating multiple hostnames use a comma separated list. Ex: test1.no-ip.biz,test2.no-ip.biz
  28. ; $sIP - The IP address to which the host(s) will be set. Default is the current IP address.
  29. ; $bOffline - Sets the current host(s) to offline status. Offline settings are an Enhanced / No-IP Plus feature.
  30. ; $bSecure - The protocol to use. If True the https protocol will be used, otherwise http. Default is True.
  31. ; Return values .: On Success - True
  32. ; On Failure -
  33. ; @error = 1 Empty Username
  34. ; @error = 2 Empty Password
  35. ; @error = 3 Empty Hostname(s)
  36. ; @error = 4 Invalid $bOffline parameter
  37. ; @error = 5 Invalid $bSecure parameter
  38. ; @error = 6 Unable to retrive the current IP address
  39. ; @error = 7 Invalid IP address
  40. ; @error = 8 Unable to contact the no-ip website
  41. ; @error = 9 Unable to retrive the no-ip source
  42. ; @error = 10 "nohost"
  43. ; @error = 11 "badauth"
  44. ; @error = 12 "badagent"
  45. ; @error = 13 "!donator"
  46. ; @error = 14 "abuse"
  47. ; @error = 15 "911"
  48. ; @error = 16 Unknown error
  49. ; Author ........: Nessie
  50. ; Example .......: _NOIP_DNSUpdate("Test", "Test", "TestME.zapto.org", "")
  51. ; ===============================================================================================================================
  52. Func _NOIP_DNSUpdate($sUser, $sPass, $sHostname, $sIP = "", $bOffline = False, $bSecure = True)
  53. Local $iMatch, $sOffline, $sProtocol
  54. If $sUser = "" Then Return SetError(1, 0, "")
  55. If $sPass = "" Then Return SetError(2, 0, "")
  56. If $sHostname = "" Then Return SetError(3, 0, "")
  57. If Not IsBool($bOffline) Then Return SetError(4, 0, "")
  58. If Not IsBool($bSecure) Then Return SetError(5, 0, "")
  59. If $sIP = "" Then
  60. $sIP = __NOIP_GetIpAddress()
  61. If @error Then Return SetError(6, 0, "")
  62. EndIf
  63. ;Thanks to http://tools.netshiftmedia.com/regexlibrary/# for this regex
  64. $iMatch = StringRegExp($sIP, "^((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){3}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})$", 0)
  65. If Not $iMatch Then Return SetError(7, 0, "")
  66. If $bOffline Then
  67. $sOffline = "YES"
  68. Else
  69. $sOffline = "NO"
  70. EndIf
  71. If $bSecure Then
  72. $sProtocol = "https"
  73. Else
  74. $sProtocol = "http"
  75. EndIf
  76. Local $bRead = InetRead($sProtocol & "://" & $sUser & ":" & $sPass & "@dynupdate.no-ip.com/nic/update?hostname=" & $sHostname & "&myip=" & $sIP & "&offline=" & $sOffline)
  77. If @error Then Return SetError(8, 0, "")
  78. Local $sRead = BinaryToString($bRead)
  79. If @error Then Return SetError(9, 0, "")
  80. Switch $sRead
  81. Case StringInStr($sRead, "good ") Or StringInStr($sRead, "nochg ")
  82. Return True
  83. Case "nohost"
  84. Return SetError(10, 0, "")
  85. Case "badauth"
  86. Return SetError(11, 0, "")
  87. Case "badagent"
  88. Return SetError(12, 0, "")
  89. Case "!donator"
  90. Return SetError(13, 0, "")
  91. Case "abuse"
  92. Return SetError(14, 0, "")
  93. Case "911"
  94. Return SetError(15, 0, "")
  95. Case Else
  96. Return SetError(16, 0, "")
  97. EndSwitch
  98. EndFunc ;==>_NOIP_DNSUpdate
  99. ; #FUNCTION# ====================================================================================================================
  100. ; Name ..........: _NOIP_HostnameResolve
  101. ; Description ...: Converts a no-ip address to IP address.
  102. ; Syntax ........: _NOIP_HostnameResolve($sAddress)
  103. ; Parameters ....: $sAddress - The no-ip hostname address
  104. ;Return values .: On Success - Returns string containing IP address corresponding to the name.
  105. ; On Failure -
  106. ; @error = 1 Unable to retrive the IP address
  107. ; Author ........: Nessie
  108. ; Example .......: _NOIP_HostnameResolve("TestME.zapto.org")
  109. ; ===============================================================================================================================
  110. Func _NOIP_HostnameResolve($sAddress)
  111. TCPStartup()
  112. Local $aResult = TCPNameToIP($sAddress)
  113. If @error Then Return SetError(1, 0, "")
  114. TCPShutdown()
  115. Return $aResult
  116. EndFunc ;==>_NOIP_HostnameResolve
  117. ; #INTERNAL_USE_ONLY# ===========================================================================================================
  118. ; Name ..........: __NOIP_GetIpAddress
  119. ; Description ...: Retrive the current IP address
  120. ; Syntax ........: __NOIP_GetIpAddress()
  121. ;Return values .: On Success - Returns string containing IP address corresponding to the name.
  122. ; On Failure -
  123. ; @error = 1 Unable to contact the server
  124. ; @error = 2 Unable to retrive the IP address
  125. ; Author ........: Nessie
  126. ; Example .......: __NOIP_GetIpAddress()
  127. ; ===============================================================================================================================
  128. Func __NOIP_GetIpAddress()
  129. Local $bRead, $sRead, $aResult
  130. $bRead = InetRead("http://checkip.dyndns.org")
  131. If @error Then Return SetError(1, 0, "")
  132. $sRead = BinaryToString($bRead)
  133. If @error Then Return SetError(2, 0, "")
  134. $aResult = StringRegExp($sRead, "(?s)(?i)<body>Current IP Address: (.*?)</body>", 3)
  135. If Not @error Then Return $aResult[0]
  136. $bRead = InetRead("http://api.exip.org/?call=ip")
  137. If @error Then Return SetError(1, 0, "")
  138. $sRead = BinaryToString($bRead)
  139. If @error Then Return SetError(2, 0, "")
  140. Return $bRead
  141. EndFunc ;==>__NOIP_GetIpAddress

comments powered by Disqus