i solved the problem:
public DynDnsUpdateResult UpdateIP(IPAddress ip)
{
byte[] data = new byte[1024];
string response = "";
int count;
// Syntax zum Aufruf:
http://www.dyndns.org/developers/specs/syntax.html
Socket socket = new Socket(AddressFamily.InterNetwork,
SocketType.Stream,ProtocolType.Tcp);
IPHostEntry host = System.Net.Dns.Resolve("members.dyndns.org");
socket.Connect((EndPoint)(new IPEndPoint(host.AddressList[0], 80)));
if (!socket.Connected)
throw new Exception("Can´t connect to dyndns service");
string request = "GET /nic/update?" +
"system=dyndns" +
"&hostname=" + mDomain +
"&myip=" + ip.ToString() +
"&wildcard=" + (mWildcard ? "ON" : "OFF") +
"&offline=NO " +
"HTTP/1.1\r\n" +
"Host: members.dyndns.org\r\n" +
"Authorization: Basic " +
System.Convert.ToBase64String(ASCIIEncoding.ASCII. GetBytes(mUsername + ":" +
mPassword)) + "\r\n" +
"User-Agent: .net dyndns client\r\n\r\n";
count = socket.Send(System.Text.UnicodeEncoding.ASCII.GetB ytes(request));
while((count = socket.Receive(data)) != 0) // Antwort von Server
response += System.Text.ASCIIEncoding.ASCII.GetString(data, 0, count);
socket.Shutdown(SocketShutdown.Both);
socket.Close();
response = response.Substring(response.IndexOf("\r\n\r\n") + 4); // Html
Header entfernen
switch (response.Substring(0, response.IndexOf(" ")).ToLower())
{
case "good":
// The update was successful, and the hostname is now updated
return DynDnsUpdateResult.UpdatedIp;
case "nochg":
// The update changed no settings, and is considered abusive.
Additional nochg updates will cause the hostname to become blocked
return DynDnsUpdateResult.NoUpdateSameIp;
case "badsys":
throw new Exception("The system parameter given is not valid. Valid
system parameters are dyndns, statdns and custom");
case "badagent":
throw new Exception("The user agent that was sent has been blocked for
not following these specifications or no user agent was specified");
case "badauth":
throw new Exception("The username or password specified are
incorrect");
case "!donator":
throw new Exception("An option available only to credited users (such
as offline URL) was specified, but the user is not a credited user");
case "notfqdn":
throw new Exception("The hostname specified is not a fully-qualified
domain name (not in the form hostname.dyndns.org or domain.com)");
case "nohost":
throw new Exception("The hostname specified does not exist (or is not
in the service specified in the system parameter)");
case "!yours":
throw new Exception("The hostname specified exists, but not under the
username specified");
case "abuse":
throw new Exception("The hostname specified is blocked for update
abuse");
case "numhost":
throw new Exception("Too many or too few hosts found");
case "dnserr":
throw new Exception("DNS error encountered");
case "911":
throw new Exception("There is a serious problem on our side, such as a
database or DNS server failure. The client should stop updating until
notified via the status page that the service is back up.");
default:
throw new Exception("Unknown result from dyndns service");
}
#endregion
}
"André Heuer" <ah****@t-online.de> schrieb im Newsbeitrag
news:ua**************@TK2MSFTNGP10.phx.gbl...
Hi,
i want to write a .net class that can update my ip address at the dyndns
service (http://www.dyndns.org).
When I open the page
https://username:pa******@members.dy...re&wildcard=on
i get the response
nochg 80.146.122.175
which means "No change". IP hasn´t changed. Fine.
I wrote this code in my c# class:
public void UpdateIP(IPAddress ip)
{
const string UPDATE_URL =
"https://<USER>:<PWD>@members.dyndns.org/nic/update?system=dyndns&hostname=< HOST>&myip=<IP>&wildcard=<WILDCARD>";
string url = UPDATE_URL;
url = url.Replace("<USER>", mUsername);
url = url.Replace("<PWD>", mPassword);
url = url.Replace("<HOST>", mDomain);
url = url.Replace("<IP>", ip.ToString());
url = url.Replace("<WILDCARD>", mWildcard ? "on" : "off");
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
request.Headers.Add("Cache-control", "no-cache");
request.Headers.Add("Pragma","no-cache");
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
string text = new
StreamReader(response.GetResponseStream()).ReadToE nd();
}
I get the following error on the line "HttpWebResponse response =
(HttpWebResponse)request.GetResponse();":
'System.Net.WebException' in system.dll
Remote Server returned an error (403) Unzulässig.
What is the difference betwenn the browser and my code? Any ideas?
Tia
André Heuer