有没有大神会写在linux下的用java实现宽带的拨号程序

有没有大神会写在linux下的用java实现宽带的拨号程序,第1张

package cn.adsl

import java.io.BufferedReader

import java.io.InputStreamReader

public class ConnectNetWork {

/**

* 执行CMD命令,并返回String字符串

*

* @param strCmd

* @return

* @throws Exception

*/

public static String exeCmd(String strCmd) throws Exception {

Process p = Runtime.getRuntime().exec("cmd /c " + strCmd)

StringBuilder sbCmd = new StringBuilder()

BufferedReader br = new BufferedReader(new InputStreamReader(p

.getInputStream()))

String line = null

while ((line = br.readLine()) != null) {

sbCmd.append(line + "\n")

}

return sbCmd.toString()

}

/**

* 切断ADSL

*

* @param adslTitle

* @return

* @throws Exception

*/

public static boolean cutAdsl(String adslTitle) throws Exception {

// 加上"" 防止空格

String cutAdsl = "rasdial \"" + adslTitle + "\" /disconnect"

String result = exeCmd(cutAdsl)

if (result.indexOf("没有连接") != -1) {

System.err.println(adslTitle + "连接不存在!")

return false

} else {

System.out.println("连接已断开")

return true

}

}

/**

* 连接ADSL

*

* @param adslTitle

* @param adslName

* @param adslPass

* @param adslPhone

* @return

* @throws Exception

*/

public static boolean connAdsl(String adslTitle, String adslName,

String adslPass, String adslPhone) throws Exception {

// 加上"" 防止空格

String adslCmd = "rasdial \"" + adslTitle + "\" " + adslName + " "

+ adslPass + " /phone:" + adslPhone

String tempCmd = exeCmd(adslCmd)

if (tempCmd.indexOf("已连接") >0) {

System.out.println("已成功建立连接.")

return true

} else {

System.err.println(tempCmd)

System.err.println("建立连接失败")

return false

}

}

/**

* @param args

*/

public static void main(String[] args) throws Exception {

// rasdial "宽带名" /disconnect

String adsl = "宽带名"

String username = "username"

String password = "password"

String phone = "#12345678"

cutAdsl(adsl)

Thread.sleep(4000)

// rasdial "宽带名" 用户名 密码 /phone:#123456789

connAdsl(adsl, username, password, phone)

}

}

官方注释方法

类html标签实现的,可以对解释文本的特殊处理,比如加重、换行、段落等。

请点击输入图片描述

固定标签author、beaninfo、see等。

请点击输入图片描述

END

IDE注释方法

新建类时候自动生成类注释标签,需提前配置。

windown-preferences->java-code style->code templetes->comments-types.

请点击输入图片描述

给已有类添加类注释说明。在类上方依次键入/**回车,添加注释说明,如果IDE已经配置模板,则会按照模板添加注释说明模板。

请点击输入图片描述


欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/yw/11536863.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-05-16
下一篇2023-05-16

发表评论

登录后才能评论

评论列表(0条)

    保存