使用ADSL上网的同学可以在家里建一个免费的网站了,不过速度可不敢恭维。
其实也就是获取外网IP,然后更新mycool.net的免费域名信息。这样,当你的ADSL断网后再重拨,获得的新IP能及时的更新到你的免费域名系统中。
需要上www.mycool.net申请一个免费域名,修改一下代码中用户名和密码,运行就OK了。
import
java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import java.text.MessageFormat;
public final class Main ... {
private static String oldIP = "";
public static void main(String[] args) ...{
while(true) ...{
String ip = getWanIP();
if (!oldIP.equals(ip)) ...{
updateDomainInfo("yourname", "oldpass", "newpass", "yourmail.domain.com", ip);
oldIP = ip;
}
try ...{
Thread.sleep(1000*60);
} catch (InterruptedException e) ...{
e.printStackTrace();
}
}
}
private static String getWanIP() ...{
BufferedReader in = null;
try ...{
URL url = new URL("http://vip.cn99.com/ret.php");
in = new BufferedReader(new InputStreamReader(url.openStream()));
String str = in.readLine();
return str;
} catch (MalformedURLException e) ...{
} catch (IOException e) ...{
} finally ...{
if (in != null)
try ...{
in.close();
}catch(IOException e) ...{}
}
return null;
}
private static void updateDomainInfo(String user, String pass, String newpass, String email, String ip) ...{
try ...{
String data = "action=modifybio&username={0}&password={1}&Email={2}&NewPassword={3}&URL=http%3A%2F%2F{4}&dirtype=no&Submit=%C8%B7%B6%A8%D0%DE%B8%C4";
data = MessageFormat.format(data, new String[]...{user, pass, email, newpass, ip});
URL url = new URL("http://mycool.net/cgi-bin/modi.cgi");
URLConnection conn = url.openConnection();
conn.setDoOutput(true);
OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream());
wr.write(data);
wr.flush();
BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
String line;
while ((line = rd.readLine()) != null) ...{
}
wr.close();
rd.close();
System.out.println("Update domain to :" + ip);
} catch (Exception e) ...{
e.printStackTrace();
}
}
}
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import java.text.MessageFormat;
public final class Main ... {
private static String oldIP = "";
public static void main(String[] args) ...{
while(true) ...{
String ip = getWanIP();
if (!oldIP.equals(ip)) ...{
updateDomainInfo("yourname", "oldpass", "newpass", "yourmail.domain.com", ip);
oldIP = ip;
}
try ...{
Thread.sleep(1000*60);
} catch (InterruptedException e) ...{
e.printStackTrace();
}
}
}
private static String getWanIP() ...{
BufferedReader in = null;
try ...{
URL url = new URL("http://vip.cn99.com/ret.php");
in = new BufferedReader(new InputStreamReader(url.openStream()));
String str = in.readLine();
return str;
} catch (MalformedURLException e) ...{
} catch (IOException e) ...{
} finally ...{
if (in != null)
try ...{
in.close();
}catch(IOException e) ...{}
}
return null;
}
private static void updateDomainInfo(String user, String pass, String newpass, String email, String ip) ...{
try ...{
String data = "action=modifybio&username={0}&password={1}&Email={2}&NewPassword={3}&URL=http%3A%2F%2F{4}&dirtype=no&Submit=%C8%B7%B6%A8%D0%DE%B8%C4";
data = MessageFormat.format(data, new String[]...{user, pass, email, newpass, ip});
URL url = new URL("http://mycool.net/cgi-bin/modi.cgi");
URLConnection conn = url.openConnection();
conn.setDoOutput(true);
OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream());
wr.write(data);
wr.flush();
BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
String line;
while ((line = rd.readLine()) != null) ...{
}
wr.close();
rd.close();
System.out.println("Update domain to :" + ip);
} catch (Exception e) ...{
e.printStackTrace();
}
}
}