很晚了,直接上代码:
/**
* 获取外网的IP(要访问Url,要放到后台线程里处理)
*
* @Title: GetNetIp
* @Description:
* @param @return
* @return String
* @throws
*/
public static String GetNetIp() {
URL infoUrl = null;
InputStream inStream = null;
String ipLine = "";
HttpURLConnection httpConnection = null;
try {
infoUrl = new URL("http://ip168.com/");
URLConnection connection = infoUrl.openConnection();
httpConnection = (HttpURLConnection) connection;
int responseCode = httpConnection.getResponseCode();
if (responseCode == HttpURLConnection.HTTP_OK) {
inStream = httpConnection.getInputStream();
BufferedReader reader = new BufferedReader(
new InputStreamReader(inStream, "utf-8"));
StringBuilder strber = new StringBuilder();
String line = null;
whi