java adsl 自动拔号!

蜘蛛服务器放在内网,用adsl拨号,老断网,自己编写了个自动拨号的程序,方法思路和大家分享一下!

Rasdial.java:

    public void runbat() {
String cmd = "cmd /c start D:/rasdial.bat";
try {
Process ps = Runtime.getRuntime().exec(cmd);
System.out.println(ps.getInputStream());
} catch (IOException ioe) {
ioe.printStackTrace();
}

}

public void work() {
try {
InetAddress ad = InetAddress.getByName("119.75.217.56");
boolean state = ad.isReachable(5000); // 测试是否可以达到该地址
if (state) {
System.err.println("连接" + ad.getHostAddress() + "成功...");
} else {
System.err.println("连接" + ad.getHostAddress() + "失败!尝试重新拨号....");
runbat();
}
} catch (IOException ioe) {
System.err.println("重新拨号失败...");
ioe.printStackTrace();
}
}

rasdial.bat文件(windows rasdial 命令)

rasdial.exe  /disconnect
rasdial.exe 连接名 用户名 密码


定时器:

<!-- 重新拨号-->
<bean id="Rasdial" class="*.*.*.*.Rasdial">
</bean>
<bean id="jobDetailRasdial" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
<property name="targetObject" ref="Rasdial" />
<property name="targetMethod" value="run" />
<property name="concurrent" value="false" />
</bean>
<bean id="cronTriggerRasdial" class="org.springframework.scheduling.quartz.CronTriggerBean">
<property name="jobDetail" ref="jobDetailRasdial" />
<property name="cronExpression" value="0 0/30 * * * ?" />
<property name="startDelay" value="4000" />
</bean>


<!-- 执行触发器 -->
<bean id="schedulerFactory"
class
="org.springframework.scheduling.quartz.SchedulerFactoryBean">
<property name="triggers">
<list>

<!-- 拨号 -->
<ref bean="cronTriggerRasdial" />
</list>
</property>
</bean>
原文地址:https://www.cnblogs.com/linyu/p/2193965.html