i solved the problem:
public DynDnsUpdateRes ult UpdateIP(IPAddr ess 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(AddressF amily.InterNetw ork,
SocketType.Stre am,ProtocolType .Tcp);
IPHostEntry host = System.Net.Dns. Resolve("member s.dyndns.org");
socket.Connect( (EndPoint)(new IPEndPoint(host .AddressList[0], 80)));
if (!socket.Connec ted)
throw new Exception("Can´ t connect to dyndns service");
string request = "GET /nic/update?" +
"system=dyn dns" +
"&hostname= " + mDomain +
"&myip=" + ip.ToString() +
"&wildcard= " + (mWildcard ? "ON" : "OFF") +
"&offline=N O " +
"HTTP/1.1\r\n" +
"Host: members.dyndns. org\r\n" +
"Authorizat ion: Basic " +
System.Convert. ToBase64String( ASCIIEncoding.A SCII.GetBytes(m Username + ":" +
mPassword)) + "\r\n" +
"User-Agent: .net dyndns client\r\n\r\n" ;
count = socket.Send(Sys tem.Text.Unicod eEncoding.ASCII .GetBytes(reque st));
while((count = socket.Receive( data)) != 0) // Antwort von Server
response += System.Text.ASC IIEncoding.ASCI I.GetString(dat a, 0, count);
socket.Shutdown (SocketShutdown .Both);
socket.Close();
response = response.Substr ing(response.In dexOf("\r\n\r\n ") + 4); // Html
Header entfernen
switch (response.Subst ring(0, response.IndexO f(" ")).ToLower ())
{
case "good":
// The update was successful, and the hostname is now updated
return DynDnsUpdateRes ult.UpdatedIp;
case "nochg":
// The update changed no settings, and is considered abusive.
Additional nochg updates will cause the hostname to become blocked
return DynDnsUpdateRes ult.NoUpdateSam eIp;
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("Ther e 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("Unkn own result from dyndns service");
}
#endregion
}
"André Heuer" <ah****@t-online.de> schrieb im Newsbeitrag
news:ua******** ******@TK2MSFTN GP10.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(IPAddr ess ip)
{
const string UPDATE_URL =
"https://<USER>:<PWD>@me mbers.dyndns.or g/nic/update?system=d yndns&hostname= < HOST>&myip=<IP> &wildcard=<WILD CARD>";
string url = UPDATE_URL;
url = url.Replace("<U SER>", mUsername);
url = url.Replace("<P WD>", mPassword);
url = url.Replace("<H OST>", mDomain);
url = url.Replace("<I P>", ip.ToString());
url = url.Replace("<W ILDCARD>", mWildcard ? "on" : "off");
HttpWebRequest request = (HttpWebRequest )WebRequest.Cre ate(url);
request.Headers .Add("Cache-control", "no-cache");
request.Headers .Add("Pragma"," no-cache");
HttpWebResponse response = (HttpWebRespons e)request.GetRe sponse();
string text = new
StreamReader(re sponse.GetRespo nseStream()).Re adToEnd();
}
I get the following error on the line "HttpWebRespons e response =
(HttpWebRespons e)request.GetRe sponse();":
'System.Net.Web Exception' 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