Java implements Dynamic IP address switching (ADSL dial-up Internet access) and adsl dial-up Internet access
The Implementation of Dynamic IP switching is also provided by the Windows rasdial command. In fact, it is not java's credit. java only calls the bat script:
Rasdial command:
Dialing
Java code
- Syntax: rasdial connection name username password
- Example: rasdial my broadband hzhz1234567890 dfdfdfdfdf
Network disconnection
Java code
- Syntax: rasdial connection name/disconnect
- Instance: rasdial broadband/disconnect
The java program calls the rasdial command:
Java code
- Package com. sesame. network;
- Import java. io. BufferedReader;
- Import java. io. InputStreamReader;
- Public class ConnectNetWork {
- /**
- * Run the CMD command and return the String.
- */
- Public static String executeCmd (String strCmd) throws Exception {
- Process p = runtime.getruntime(cmd.exe c ("cmd/c" + strCmd );
- StringBuilder sbCmd = new StringBuilder ();
- BufferedReader br = new BufferedReader (new InputStreamReader (p
- . GetInputStream ()));
- String line;
- While (line = br. readLine ())! = Null ){
- SbCmd. append (line + "\ n ");
- }
- Return sbCmd. toString ();
- }
- /**
- * Connect to ADSL
- */
- Public static boolean connAdsl (String adslTitle, String adslName, String adslPass) throws Exception {
- System. out. println ("establishing connection .");
- String adslCmd = "rasdial" + adslTitle + "" + adslName + ""
- + AdslPass;
- String tempCmd = executeCmd (adslCmd );
- // Determine whether the connection is successful
- If (tempCmd. indexOf ("connected")> 0 ){
- System. out. println ("Connection established successfully .");
- Return true;
- } Else {
- System. err. println (tempCmd );
- System. err. println ("failed to establish a connection ");
- Return false;
- }
- }
- /**
- * Disconnect ADSL
- */
- Public static boolean cutAdsl (String adslTitle) throws Exception {
- String cutAdsl = "rasdial" + adslTitle + "/disconnect ";
- String result = executeCmd (cutAdsl );
- If (result. indexOf ("no connection ")! =-1 ){
- System. err. println (adslTitle + "the connection does not exist! ");
- Return false;
- } Else {
- System. out. println ("disconnected ");
- Return true;
- }
- }
- Public static void main (String [] args) throws Exception {
- ConnAdsl ("Broadband", "hzhz **********","******");
- Thread. sleep (1000 );
- CutAdsl ("Broadband ");
- Thread. sleep (1000 );
- // Re-connect and assign a new IP Address
- ConnAdsl ("Broadband", "hzhz **********","******");
- }
- }
Execution result:
Java code
- Establishing connection.
- The connection has been established successfully.
- Disconnected
- Establishing connection.
- The connection has been established successfully.
Summary:
The most important thing to implement this function is that the bat command can support this function, which is similar to the previously written function of automatically setting ip addresses. it is inconvenient to implement these functions in java, it seems that it is necessary to elegantly implement the behaviors related to the windows operating system and learn windows programming.
How does the dynamic IP address change when the ADSL dial-up accesses the Internet?
The IP address is changed only after, for example, A. B .C.D. C and D are changed.
Do you want to change the QQ password or forget the QQ password statement?
If you know your QQ password, you only need to answer your security questions.
If you forget your QQ password, you need to answer the questions you have logged on to, the passwords you used before, the time when you applied for the QQ number for the first time, and so on.
You don't have to change the QQ password because you have doubts !!
How can I change the Internet IP address for adsl dial-up access?
Cannot be modified. You are using the dynamic IP address automatically assigned to you by China Telecom. You cannot modify it yourself. If you change the IP address, you can switch the adsl cat again to automatically obtain the new IP address.
It cannot be modified by individuals. It is easy to understand that if the IP addresses on the public network can be modified freely by hundreds of millions of people around the world, frequent Ip address conflicts may occur, no one can use the internet normally.