首页上一页 1 下一页尾页 3 条记录 1/1页
java IP 急
发表在Java图书答疑
2009-04-01
是否精华
是
否
版块置顶:
是
否
我想请教一个问题:
下面是代码一:
package ip;
import java.io.IOException;
import javax.swing.JOptionPane;
public class Neusoft_IP {
/**
* @param args
*/
public static void main(String[] args)
{
Object[] options={"宿舍","A102","C201","A410","B103"};
Object n=JOptionPane.showInputDialog(null, "你所在的位置?", "IP切换", JOptionPane.DEFAULT_OPTION, null, options, options[0]);
if(n=="宿舍")
try {
Runtime.getRuntime().exec( "Netsh interface ip set address \"本地连接\" static 10.1.43.154 255.255.255.0 10.1.43.254 1");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
if(n=="A102")
try {
Runtime.getRuntime().exec( "Netsh interface ip set address \"本地连接\"172.26.22.154 255.255.255.0 172.26.22.254 1");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
if(n=="C201")
try {
Runtime.getRuntime().exec( "Netsh interface ip set address \"本地连接\" static 172.26.104.154 255.255.255.0 172.26.104.254 1");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
if(n=="A410")
try {
Runtime.getRuntime().exec( "Netsh interface ip set address \"本地连接\" static 172.26.63.154 255.255.255.0 172.26.63.254 1");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
if(n=="B103")
try {
Runtime.getRuntime().exec( "Netsh interface ip set address \"本地连接\" static 172.26.41.154 255.255.255.0 172.26.41.254 1");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
代码二:
public int getIp(){
boolean ok = true;
double num = Math.random()*1000;
int ip4 = (int)num;
while(ok){
if(ip4<=255){
ok = false;
}
else{
ip4 = (int)(Math.random()*1000);
}
}
return ip4;
}
我想要把两个代码合起来,实现第四位IP的动态获得。
但水平有限
希望能帮我把代码,给改改。
谢谢。
下面是代码一:
package ip;
import java.io.IOException;
import javax.swing.JOptionPane;
public class Neusoft_IP {
/**
* @param args
*/
public static void main(String[] args)
{
Object[] options={"宿舍","A102","C201","A410","B103"};
Object n=JOptionPane.showInputDialog(null, "你所在的位置?", "IP切换", JOptionPane.DEFAULT_OPTION, null, options, options[0]);
if(n=="宿舍")
try {
Runtime.getRuntime().exec( "Netsh interface ip set address \"本地连接\" static 10.1.43.154 255.255.255.0 10.1.43.254 1");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
if(n=="A102")
try {
Runtime.getRuntime().exec( "Netsh interface ip set address \"本地连接\"172.26.22.154 255.255.255.0 172.26.22.254 1");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
if(n=="C201")
try {
Runtime.getRuntime().exec( "Netsh interface ip set address \"本地连接\" static 172.26.104.154 255.255.255.0 172.26.104.254 1");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
if(n=="A410")
try {
Runtime.getRuntime().exec( "Netsh interface ip set address \"本地连接\" static 172.26.63.154 255.255.255.0 172.26.63.254 1");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
if(n=="B103")
try {
Runtime.getRuntime().exec( "Netsh interface ip set address \"本地连接\" static 172.26.41.154 255.255.255.0 172.26.41.254 1");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
代码二:
public int getIp(){
boolean ok = true;
double num = Math.random()*1000;
int ip4 = (int)num;
while(ok){
if(ip4<=255){
ok = false;
}
else{
ip4 = (int)(Math.random()*1000);
}
}
return ip4;
}
我想要把两个代码合起来,实现第四位IP的动态获得。
但水平有限
希望能帮我把代码,给改改。
谢谢。