473,469 Members | 1,513 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

DynDns Update with c# client

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.dyndns.org/nic/update?system=dyndns&hostname=MyHostNameHere&myip= MyCurrentIpHere&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:
Expand|Select|Wrap|Line Numbers
  1. public void UpdateIP(IPAddress ip)
  2. {
  3.     const string UPDATE_URL =
  4. "https://<USER>:<PWD>@members.dyndns.org/nic/update?system=dyndns&hostname=<
  5. HOST>&myip=<IP>&wildcard=<WILDCARD>";
  6.  
  7.     string url = UPDATE_URL;
  8.     url = url.Replace("<USER>", mUsername);
  9.     url = url.Replace("<PWD>", mPassword);
  10.     url = url.Replace("<HOST>", mDomain);
  11.     url = url.Replace("<IP>", ip.ToString());
  12.     url = url.Replace("<WILDCARD>", mWildcard ? "on" : "off");
  13.  
  14.     HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
  15.  
  16.     request.Headers.Add("Cache-control", "no-cache");
  17.     request.Headers.Add("Pragma","no-cache");
  18.  
  19.     HttpWebResponse response = (HttpWebResponse)request.GetResponse();
  20.     string text = new StreamReader(response.GetResponseStream()).ReadToEnd();
  21.  
  22. }
I get the following error on the line
Expand|Select|Wrap|Line Numbers
  1. "HttpWebResponse response =
  2. (HttpWebResponse)request.GetResponse();":
  3.  
  4. 'System.Net.WebException' in system.dll
  5. Remote Server returned an error (403) Unzulässig.
What is the difference between the browser and my code? Any ideas?

Tia

André Heuer
Nov 15 '05 #1
2 14910
Additional information. This code in vbs works fine.....

Function UpdateDynDnsService(user,password,hostname,ipaddre ss,wildcard)
Dim xmlhttp,url,startPos,endPos,tempCmd

set xmlhttp = createobject("microsoft.xmlhttp")
tempCmd = DYNDNSUPDATECMD
tempCmd = replace(DYNDNSUPDATECMD,"<USER>",user)
tempCmd = replace(tempCmd,"<PWD>",password)
tempCmd = replace(tempCmd,"<HOST>",hostname)
tempCmd = replace(tempCmd,"<IP>",ipaddress)
tempCmd = replace(tempCmd,"<WILDCARD>",wildcard)
url = tempCmd
xmlhttp.open "get",url,false

wscript.echo tempcmd

xmlhttp.setrequestheader "Pragma","no-cache"
xmlhttp.setrequestheader "Cache-control","no-cache"
On Error Resume Next
xmlhttp.send
If Err.Number<>0 Then
UpdateDynDnsService = "Fail"
Exit Function
End If
On Error Goto 0
If (xmlhttp.Status = 200) then
UpdateDynDnsService = CStr(xmlhttp.responsetext)
Else
If (xmlhttp.Status = 401) then
UpdateDynDnsService = "badauth"
Else
UpdateDynDnsService = "Fail"
End If
End If
End Function
Nov 15 '05 #2
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

Nov 15 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Andrew | last post by:
I've got a list box that selects a record on a subform, and in that subform are a few text fiels and a button that runs an update query. How do I have the update query button run and only update...
4
by: CaptRR | last post by:
I think this is the right group to post to, so here goes. My problem is this, I cannot update the datarow to save my life. Been on this for 2 days now, and still am no closer to figuring it out...
17
by: Zvi Danovich | last post by:
Hi, I am a newby in ASP.NET, and till now wrote only simple "classic" WEB-sites. But - the time came, and now I need that: 1. Server will "listen" for some events on its local machine 2....
4
by: Jim Hammond | last post by:
It would be udeful to be able to get the current on-screen values from a FormView that is databound to an ObjectDataSource by using a callback instead of a postback. For example: public void...
9
by: Kevin Hodgson | last post by:
I'm experiencing a strange Dataset Update problem with my application. I have a dataset which has a table holding a set of customer information records. (address, contact, info, etc.) I have a...
2
by: bobabooey2k | last post by:
I have an update query with one field having in its "Update to" cell a DLookup statement. This query takes 2-3 minutes on 3000 records. Can I avoid dlookup here using multiple queries? An...
6
by: Rudy | last post by:
Hello all! I'm working in vb/ado.net I want to to have a message box pop up based on a result of a update on a SQL table. How do I do that so it automaticly pops up after the update is...
5
by: HockeyFan | last post by:
We have an update panel that has a gridview with checkboxes and other items in each row. We went to the RowCreated event in the codebehind, to set an attribute on a checkbox in each row, to...
2
by: Stephan Schulz | last post by:
Hi all, I need an application that will duplicate an incoming stream of UDP messages and send it on to some external server that has a dynamic DNS address. I can use the dynamic name...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.