Your Ad Here
首页 | 编程语言 | 网站建设 | 游戏天堂 | 冲浪宝典 | 网络安全 | 操作系统 | 软件时空 | 硬件指南 | 病毒相关 | IT 认证
软讯网络 > 编程语言 > Java > 自动设置WindowsIP的程序SetupIP
【标  题】:自动设置WindowsIP的程序SetupIP
【关键字】:WindowsIP,SetupIP
【来  源】:http://blog.csdn.net/JavaWHB/archive/2007/02/16/1511037.aspx

自动设置WindowsIP的程序SetupIP

Your Ad Here

开发原因: 上大学时使用教育网,抢IP是个令人头痛的问题,昨天还能用的IP今天早上起来就被别人占了,十分郁闷,于是做了一个自动试设IP的程序。原理很简单,使用了Windows的两个程序:netsh和ipconfig,使用netsh设置IP,如果成功了,用ipconfig就会得到有效的IP,否则就是0.0.0.0的无效IP,根据这个判断是否成功设置。

使用方法:需更改“String todo = "netsh interface ip set address 本地连接 static 222.28.34.%1 255.255.255.0 222.28.34.1 0";”和代码中的IP地址换成你机器所用的网段。

适用对象:Java初学者。

注:该程序可很容易移植到其他操作系统,只要替换其中的本机程序就行。

//忘忧草工作室
//2007-2-16


import java.io.*;
public class SetupIP {
    
public static void main(String[] args) {
        String todo 
= "netsh interface ip set address 本地连接 static 222.28.34.%1 255.255.255.0 222.28.34.1 0";
        String cmd 
= null;
        
try {
            
for (int i = 254; i > 1; i --) {
                cmd 
= todo.replaceAll("%1",String.valueOf(i));
                Process p 
= Runtime.getRuntime().exec(cmd);
                p.waitFor();
                Process pp 
= Runtime.getRuntime().exec("ipconfig");
                pp.waitFor();
                BufferedReader stdInput 
= new BufferedReader(new InputStreamReader(pp.getInputStream()));
                String s 
= null;
                StringBuffer ss 
= new StringBuffer();
                
while ((s = stdInput.readLine()) != null) {
                    ss.append(s);
                }
                
if (ss.indexOf("222.28.34"> 0) {
                    System.out.println(
"当前IP设置为:222.28.34." + String.valueOf(i));
                    System.exit(
0);
                }
            }
        } 
catch (Exception e) {
            e.printStackTrace();
        }
    }
}
lucene并行建索引解决方案:【上一篇】
How-To Develop EJB 3.0 to Supports Backward Compatibility with EJB 2.x Clients:【下一篇】
【相关文章】
没有相关文章
【随机文章】
  • 帮朋友安装了一下debian
  • 郎咸平教授谈上海房价
  • 大话西游2 浅谈高级鞋
  • 突破防火墙常用的几种技术
  • 身份管理三步曲
  • 网络免费短信逐个数
  • ARM与Thumb状态切换及其代码分析
  • 看了很让人感动的一个帖子
  • JAVA/JSP学习系列之十(JavaMail API发邮件[servlet])
  • 轻松获得网通、电信、铁通IP分配范围
  • 【相关评论】
    没有相关评论
    【发表评论】
    姓名:
    邮件:
    随机码*
    评论*
          
    |  首 页  |  版权声明  |  联系我们   |  网站地图  |
    CopyRight © 2004-2007 软讯网络 All Rigths Reserved.