Monday, September 19, 2011

PAW and DynDNS

From time to time I get requests from users who would like to have a DynDNS integration into PAW.
I thought about it ... but it just doesn't make much sense, because there are enough apps in the Android Market that do exactly this.
So I will not provide a plug-in or another means of DynDNS integration, but for those of you who would like to experiment here is a basic BeanShell implementation of the DynDNS API:

import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.*;
import org.apache.http.client.methods.*;
import org.apache.http.util.*;
import org.apache.http.auth.*;

/*
    Host, username and password settings
*/
hostname = "";
user = "";
password = "";

/*
    Get IP number
*/
client = new DefaultHttpClient();  
getURL = "http://checkip.dyndns.com/";
get = new HttpGet(getURL);
responseGet = client.execute(get);  
resEntityGet = responseGet.getEntity();

if (resEntityGet != null) {
  // Extract IP number
  ip = EntityUtils.toString(resEntityGet).replaceAll(".*?([0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}).*", "$1").replaceAll("[\n\r]", "");
  print("IP: " + ip);
 
 /*
    Send DynDNS update request
 */
  updateURL= "https://members.dyndns.org/nic/update?hostname=" + hostname + "&myip=" + ip + "&wildcard=NOCHG&mx=NOCHG&backmx=NOCHG";
  get = new HttpGet(updateURL);
  client.getCredentialsProvider().setCredentials(new AuthScope(null, -1),
new UsernamePasswordCredentials(user, password));
  responseGet = client.execute(get);  
  resEntityGet = responseGet.getEntity();
  
  response = EntityUtils.toString(resEntityGet);
  success = response.startsWith("good");
  
  // Print result
  print("Response: " + response);
}


Hostname, username and password have to be inserted into the script.

This implementation is not complete but should be a good start for further development.
To start the script automatically when PAW starts, put it in the paw/autostart or paw/etc/rc.* folder.

The API is quite easy and it should not take too long to get a complete implementation up and running ...

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.