<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Chris Kankiewicz &#187; VNC</title>
	<atom:link href="http://www.chriskankiewicz.com/posts/tag/vnc/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.chriskankiewicz.com</link>
	<description>Web Design &#8226; Graphic Design &#8226; Code</description>
	<lastBuildDate>Sun, 01 Aug 2010 06:50:03 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=abc</generator>
		<item>
		<title>IP Uploader &#8211; Python Script (.py)</title>
		<link>http://www.chriskankiewicz.com/posts/2008/09/30/ip-uploader-python-script-py/</link>
		<comments>http://www.chriskankiewicz.com/posts/2008/09/30/ip-uploader-python-script-py/#comments</comments>
		<pubDate>Tue, 30 Sep 2008 09:28:17 +0000</pubDate>
		<dc:creator>Chris Kankiewicz</dc:creator>
				<category><![CDATA[Scripting]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[Cox]]></category>
		<category><![CDATA[Dynamic IP]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[Script]]></category>
		<category><![CDATA[VNC]]></category>

		<guid isPermaLink="false">http://www.chriskankiewicz.com/wp/?p=148</guid>
		<description><![CDATA[NOTE: This script can now be found here:: http://github.com/PHLAK/ip-uploader This is my first python script I ever wrote. This script connects to whatismyip.com, fetches the external IP address of the network you are on, puts it into a text file and uploads it via FTP to any server you want. At home I have Cox, [...]]]></description>
			<content:encoded><![CDATA[<p><strong>NOTE:</strong> This script can now be found here:: <a href="http://github.com/PHLAK/ip-uploader">http://github.com/PHLAK/ip-uploader</a></p>
<p>This is my first python script I ever wrote.  This script connects to <a href="http://www.whatismyip.com/" target="_blank">whatismyip.com</a>, fetches the external IP address of the network you are on, puts it into a text file and uploads it via FTP to any server you want.</p>
<p>At home I have Cox, therefore I have a dynamic IP.  Even though this IP only changes about once every month, I got sick of needing to connect to my home computer via VNC and not being able because my IP had changed.  Therefore I created the following script and set up a scheduled task on my home computer to run this script every hour.</p>
<p>After running this script, you can then use PHP (or any  similar language) to include this file into any page you desire.</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">#! /usr/bin/env python</span>
<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">httplib</span>
<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">sys</span>
<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">os</span>
<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">ftplib</span>
&nbsp;
<span style="color: #008000;">file</span>=<span style="color: #483d8b;">&quot;ip.txt&quot;</span>
&nbsp;
conn = <span style="color: #dc143c;">httplib</span>.<span style="color: black;">HTTPConnection</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;www.whatismyip.com&quot;</span><span style="color: black;">&#41;</span>
conn.<span style="color: black;">request</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;GET&quot;</span>,<span style="color: #483d8b;">&quot;/automation/n09230945.asp&quot;</span><span style="color: black;">&#41;</span>
response = conn.<span style="color: black;">getresponse</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
data = response.<span style="color: black;">read</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
&nbsp;
filename = <span style="color: #008000;">str</span><span style="color: black;">&#40;</span><span style="color: #dc143c;">os</span>.<span style="color: black;">path</span>.<span style="color: black;">abspath</span><span style="color: black;">&#40;</span><span style="color: #dc143c;">os</span>.<span style="color: black;">path</span>.<span style="color: black;">dirname</span><span style="color: black;">&#40;</span><span style="color: #dc143c;">sys</span>.<span style="color: black;">argv</span><span style="color: black;">&#91;</span><span style="color: #ff4500;">0</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span> + <span style="color: #483d8b;">&quot;<span style="color: #000099; font-weight: bold;">\\</span>&quot;</span>+<span style="color: #008000;">file</span><span style="color: black;">&#41;</span> <span style="color: #808080; font-style: italic;">#Create file</span>
FILE = <span style="color: #008000;">open</span><span style="color: black;">&#40;</span>filename,<span style="color: #483d8b;">&quot;w&quot;</span><span style="color: black;">&#41;</span> <span style="color: #808080; font-style: italic;">#Open file ready for writing</span>
FILE.<span style="color: black;">writelines</span><span style="color: black;">&#40;</span>data<span style="color: black;">&#41;</span> <span style="color: #808080; font-style: italic;">#Write 'data' to file</span>
FILE.<span style="color: black;">close</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span> <span style="color: #808080; font-style: italic;">#Close file</span>
&nbsp;
<span style="color: #808080; font-style: italic;">#Replace [server], [user], and [pass] with your information.</span>
s = <span style="color: #dc143c;">ftplib</span>.<span style="color: black;">FTP</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'[server]'</span>,<span style="color: #483d8b;">'[user]'</span>,<span style="color: #483d8b;">'[pass]'</span><span style="color: black;">&#41;</span> <span style="color: #808080; font-style: italic;">#Connect</span>
f = <span style="color: #008000;">open</span><span style="color: black;">&#40;</span><span style="color: #008000;">file</span>,<span style="color: #483d8b;">'rb'</span><span style="color: black;">&#41;</span> <span style="color: #808080; font-style: italic;">#File to send</span>
s.<span style="color: black;">storbinary</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'STOR '</span>+<span style="color: #008000;">file</span>, f<span style="color: black;">&#41;</span> <span style="color: #808080; font-style: italic;">#Send the file</span>
f.<span style="color: black;">close</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span> <span style="color: #808080; font-style: italic;">#Close file and FTP</span>
s.<span style="color: black;">quit</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span> <span style="color: #808080; font-style: italic;">#Quit FTP</span>
&nbsp;
<span style="color: #dc143c;">sys</span>.<span style="color: black;">exit</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">0</span><span style="color: black;">&#41;</span></pre></div></div>

<p>Shouts to Automated Penguin and Nak!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.chriskankiewicz.com/posts/2008/09/30/ip-uploader-python-script-py/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
