Python - My External IP Address
import urllib url = urllib.URLopener() resp = url.open('http://myip.dk') html = resp.read(114) end = html.find("</title>") start = html.find("IP:") + 3 print html[start:end].strip()
DZone Snippets > whitetiger > url
11376 users tagging and storing useful source code snippets
Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world
import urllib url = urllib.URLopener() resp = url.open('http://myip.dk') html = resp.read(114) end = html.find("</title>") start = html.find("IP:") + 3 print html[start:end].strip()
package get.file.example; import java.io.BufferedInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.net.MalformedURLException; import java.net.URL; public class GetFileExample { public GetFileExample() { try { byte[] bite = new byte[2048]; int read; URL url = new URL("http://switch.dl.sourceforge.net/sourceforge/pys60miniapps/FlickrS60_src_v0.1b.tar.bz2"); BufferedInputStream bis = new BufferedInputStream(url.openStream()); FileOutputStream fos = new FileOutputStream("/tmp/file.tar.bz2"); while((read = bis.read(bite))>0) { fos.write(bite, 0, read); System.out.println("--"); } fos.close(); bis.close(); System.out.println("FINE"); } catch(MalformedURLException e) { e.printStackTrace(); } catch(IOException e) { e.printStackTrace(); } } public static void main(String[] args) { new GetFileExample(); } }