📄 dialmanager.java
字号:
package com.gaidi.virtualnet.tini;
/**
* <p>Title: 拨号连接管理器
* <p>Description:
* 1.拨号,并保持internet活性连接
* 2.更新virtualdns地址
* 3.启动运行
* <p>Copyright: Copyright (c) 2003</p>
* <p>Company: </p>
* @author not attributable
* @version 1.0
*/
import java.net.*;
import java.io.*;
import java.util.*;
import com.gaidi.Log.Log;
public class DialManager implements Runnable{
int portID = 4;
String phoneNumber = null;
String user =null;
String password = null;
int destIndex = 0;
final String[] destHost = {
"www.sina.com.cn",
"www.163.com",
"www.google.com",
"www.sc.cninfo.net",
"www.yahoo.com",
"www.xinhua.cn",
"www.263.com",
"www.baidu.com",
"www.ibm.com",
"www.sun.com",
"www.microsoft.com",
"www.hp.com",
"www.apple.com",
"www.ge.com",
"www.siemens.com",
"www.dell.com",
"www.lenovo.com",
"www.cctv.com",
"www.china.com",
"www.chinese.com"
};
private final int RETRY_TIMES = 9;
private final int REDAIL_INTERVAL_SECOND = 45000;//毫秒
private final int MAXSLEEPSECONDS = 120000;//毫秒
private boolean isQuit = false;
PPPClient pppClient = null;
public DialManager(String phoneNumber,String user,String password) throws Exception {
this.phoneNumber = phoneNumber;
this.user = user;
this.password = password;
pppClient = new PPPClient(portID, user, password, phoneNumber);
}
public void quit(){
isQuit = true;
}
public boolean dial(boolean isHangup){
boolean result = false;
for(int i = 0;i<RETRY_TIMES;i++){
pppClient.stopPPP();
for(int j = 0;j<9;j++){
if(pppClient.status() == 1)
{
try{
Thread.currentThread().sleep(10000);
}
catch(Exception _){
}
}
else
break;
}
if(pppClient.status() == 0){
result = true;
break;
}
else{
try{
Thread.sleep(REDAIL_INTERVAL_SECOND);
}catch(Exception _){
}
}
}
return result;
}
private boolean testConnect() {
try {
if (destIndex == destHost.length)
destIndex = 0;
InetAddress address = InetAddress.getByName(destHost[destIndex++]);
if (address != null) {
return com.dalsemi.tininet.icmp.Ping.pingNode(address);
//return true;
}
}
catch (UnknownHostException _) {
}
return false;
}
void activeDial() {
long millisecond = System.currentTimeMillis();
while (!isQuit) {
try {
Thread.currentThread().sleep(15000);
}
catch (Exception _) {
}
boolean result = false;
while(result == false){
result = testConnect();
long curMillisecond = System.currentTimeMillis();
if (result) {
millisecond = curMillisecond;
}
else if (curMillisecond - millisecond > MAXSLEEPSECONDS) {
Log.writeLog("Start Redail.", true);
while (!isQuit && !dial(true))
;
Log.writeLog("Redail Success.", true);
millisecond = System.currentTimeMillis();
result = true;
}
}
}
}
public void startActiveDialThread(){
Thread cur = new Thread(this,"Dial");
cur.start();
}
public void run(){
if("Dial".equalsIgnoreCase(Thread.currentThread().getName())){
activeDial();
}
}
public static void maintest(String[] args) {
try{
DialManager dialManager = new DialManager("#777", "CARD", "CARD");
dialManager.activeDial();
}catch(Exception e){
Log.writeException(e);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -