Home > Uncategorized > servedwithpi.com – a tiny webserver

servedwithpi.com – a tiny webserver

Advertisements
Categories: Uncategorized
  1. February 15, 2013 at 10:31 pm

    Here is a website “www.servedwithpi.com”, that’s hosted on a raspberry pi device. It’s running apache, and a simple one page (one line) website. I’ve fixed the raspberry pi with a static ip, then port-forwarded my router on port 80 to the internal ip. Then I registered a domain name, and pointed to my external ip.

    My external ip is dynamic, so I expect this domain will go down tomorrow, so, I intend to use namecheap’s dns api to keep the domain updated with my latest external ip.

  2. February 20, 2013 at 7:29 pm

    I’ve fixed the dynamic ip issue using the NameCheap API, here is a video showing how: http://www.youtube.com/watch?v=8aKXxCNlbaM

    • February 24, 2013 at 3:56 pm

      Is it possible for you post the python code you used for updating your IP?

  3. February 24, 2013 at 4:40 pm

    @Paul: here is this python code:

    import httplib
    print “starting…”
    brinkster = httplib.HTTPConnection(“dananos.brinkster.net”)
    brinkster.request(“GET”, “/ip.php”)
    response = brinkster.getresponse()
    ip = response.read()
    print “got ip ” + ip
    strPostdata = “/xml.response?”
    strPostdata += “apiuser=fiach”
    strPostdata += “&apikey=xxxxxxxxxxxxxx”
    strPostdata += “&username=fiach”
    strPostdata += “&Command=namecheap.domains.dns.setHosts”
    strPostdata += “&ClientIp=82.4.23.126”
    strPostdata += “&SLD=servedwithpi”
    strPostdata += “&TLD=com”
    strPostdata += “&HostName1=www”
    strPostdata += “&RecordType1=A”
    strPostdata += “&Address1=” + ip
    strPostdata += “&MXPref1=10”
    strPostdata += “&TTL1=100”
    strPostdata += “&HostName2=www”
    strPostdata += “&RecordType2=A”
    strPostdata += “&Address2=” + ip
    strPostdata += “&MXPref2=10”
    strPostdata += “&TTL2=100”
    print “calling ” +strPostdata
    namecheap = httplib.HTTPConnection(“api.namecheap.com”)
    namecheap.request(“GET”, strPostdata)
    response2 = namecheap.getresponse()
    xml = response2.read()
    print xml
    f = open(‘namecheap.txt’, ‘w’)
    f.write(xml)
    f.close()

    I’ve omitted the apikey, you’ll need to get your own from Namecheap…

  4. March 17, 2013 at 7:08 pm

    As an update to this, you might notice that the pi makes two calls during this, one to get the remote IP address and another to update the DNS at namecheap, it’s possible to limit this to one call, and get the server to make the update. – I’ve used a brinkster host, which will have outbound ips 65.182.100.104 or 65.182.101.243, and converted my script to asp.net:

    string ip = Request.UserHostAddress;
    Response.Write(“
    IP Address:” + Request.UserHostAddress);
    Response.Write(“
    ” + DateTime.Now);
    string strPostdata = “/xml.response?”;
    strPostdata += “apiuser=fiach”;
    strPostdata += “&apikey=xxxxxxxxxxxxxxxxxxxxxxx”;
    strPostdata += “&username=fiach”;
    strPostdata += “&Command=namecheap.domains.dns.setHosts”;
    strPostdata += “&ClientIp=82.4.23.126”;
    strPostdata += “&SLD=servedwithpi”;
    strPostdata += “&TLD=com”;
    strPostdata += “&HostName1=www”;
    strPostdata += “&RecordType1=A”;
    strPostdata += “&Address1=” + ip;
    strPostdata += “&MXPref1=10”;
    strPostdata += “&TTL1=100”;
    strPostdata += “&HostName2=www”;
    strPostdata += “&RecordType2=A”;
    strPostdata += “&Address2=” + ip;
    strPostdata += “&MXPref2=10”;
    strPostdata += “&TTL2=100”;
    string strUrl = “http://api.namecheap.com” + strPostdata;
    HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(strUrl);
    HttpWebResponse response = (HttpWebResponse)request.GetResponse();
    Stream st = response.GetResponseStream();
    StreamReader sr = new StreamReader(st);
    Response.Write(sr.ReadToEnd());
    st.Close();

    For Completeness,

    My crontab line is like this
    */10 * * * * /usr/bin/python /home/pi/updateip.py

    import httplib
    brinkster = httplib.HTTPConnection(“dananos.brinkster.net”)
    brinkster.request(“GET”, “/xxxxxx.aspx”)
    response = brinkster.getresponse()
    xml = response.read()
    f = open(‘namecheap.txt’, ‘w’)
    f.write(xml)
    f.close()

    – Sorry, I had to remove the exact location of the aspx page, since if it’s requested by another ip it will affect the location of my website.

    – Perhaps a safety net of checking against the subnet mask of my ISP (TO-DO)….

  5. May 24, 2013 at 12:38 pm

    Hi ! With your script, the ClientIp field must be changed every time my external ip changes or just put it once and the script makes all ? Thank you !

  6. November 25, 2013 at 3:46 pm

    Is there a tutorial for this, only I have managed to install word press. But not sure where or how you run the Python script. Do you have to use name cheap, only I have registered my domain with UK2.net. If I had know I would have registered my domain name with Name Cheap????

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: