473,769 Members | 4,846 Online
Bytes | Software Development & Data Engineering Community
+ 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.dynd ns.org/nic/update?system=d yndns&hostname= MyHostNameHere& myip=MyCurrentI pHere&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 14957
Additional information. This code in vbs works fine.....

Function UpdateDynDnsSer vice(user,passw ord,hostname,ip address,wildcar d)
Dim xmlhttp,url,sta rtPos,endPos,te mpCmd

set xmlhttp = createobject("m icrosoft.xmlhtt p")
tempCmd = DYNDNSUPDATECMD
tempCmd = replace(DYNDNSU PDATECMD,"<USER >",user)
tempCmd = replace(tempCmd ,"<PWD>",passwo rd)
tempCmd = replace(tempCmd ,"<HOST>",hostn ame)
tempCmd = replace(tempCmd ,"<IP>",ipaddre ss)
tempCmd = replace(tempCmd ,"<WILDCARD>",w ildcard)
url = tempCmd
xmlhttp.open "get",url,f alse

wscript.echo tempcmd

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

Nov 15 '05 #3

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

Similar topics

5
4703
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 the record that is selected in the list box? The data updates right, but I can't get the update query to do anything but update all of the records. Thanks, Andrew
4
2012
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 than I was before. I'm basicly taking date from some text boxes, trying to put them into a datarow and using that datarow to update the database, but its not working. The btn_update is where I am sending the information back to the addclient...
17
2742
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. According to event received (say - event ID), it will update client pages, that need updating based on this ID (if currently there exist clients that are interesting in specific ID). The good example of such site - airport flight information, when...
4
3423
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 RaiseCallbackEvent(string eventArgs) { // update the data object with the values currently on screen FormView1.UpdateItem(true); }
9
1549
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 series of ComboBoxes (Client Number for selection), and text fields to show the other data bound to this Dataset.table If I change a value for the first client in the list, and press my update client button, the data is successfully updated to the...
2
5072
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 underlying subquery to this Update query involves a MAX function on a date field, which is then used in the DLookup statement. Any help appreciated. Thanks Richard
6
1370
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 performed? Also, is there a way to put in a variable in the message box base on the results of the Update? TIA!!
5
3446
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 execute a particular javascript function (client-side). THis is supposed to work. I've done it hundreds of times otherwise, but never in an update panel (until now). It doesn't work. I put an alert in the top of my javascript function, and it never...
2
2040
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 someserver.dyndns.org to get the current IP address or to send data too. The question I have is how to do this in the most elegant way. What happens if I just use the tuple ("someserver.dyndns.org", someport) as the address in socket.sendto()? Will the...
0
9589
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9423
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10212
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9995
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7410
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5304
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5447
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3962
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2815
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.