简体   繁体   中英

modify getInputStream & switch IP address using HTTP connect, with java

Essentially what I want to do is be able to switch my IP address between the two NIC cards on my machine, and then demonstrate that I've done so.

I'm connecting to this site to show my IP address but as you can probably imagine, the code below spits out a lot of garbage, is there a way to just get the specific words: "your IP address is XXX.XX.XX.XX"? and leave out all the rest?

Also I still don't know how I can dynamically switch my IP, is that possible using HTTP Connection as I am?

 import java.net.*;
 import java.io.*;

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

    URL oracle = new URL("http://ipaddress.com/?gclid=CIfHmL3zsr8CFYwDvAodqAEAag");


    BufferedReader in = new BufferedReader(
    new InputStreamReader(oracle.openStream()));

    String inputLine;
    while ((inputLine = in.readLine()) != null)
        System.out.println(inputLine);
    in.close();
}
}

If you are on windows you could write a bat script to do this.

You can then execute you bat from Java if you wish:

Process p1 = Runtime.getRuntime().exec("C:\\switchCon.bat");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM