public String getNetIp()
{
URL infoUrl = null;
InputStream inStream = null;
try
{
infoUrl = new URL("http://www.cz88.net/ip/viewip778.aspx");
URLConnection connection = infoUrl.openConnection();
HttpURLConnection 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;
while ((line = reader.readLine()) != null)
strber.append(line + "\n");
inStream.close();
String value = "IPMessage\">";
// 从反馈的结果中提取出IP地址
int start = strber.indexOf(value);
int end = strber.indexOf("</span>");
line = strber.substring(start + value.length(), end);
return line;
}
} catch (MalformedURLException e)
{
e.printStackTrace();
} catch (IOException e)
{
e.printStackTrace();
}
return null;
}
{
URL infoUrl = null;
InputStream inStream = null;
try
{
infoUrl = new URL("http://www.cz88.net/ip/viewip778.aspx");
URLConnection connection = infoUrl.openConnection();
HttpURLConnection 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;
while ((line = reader.readLine()) != null)
strber.append(line + "\n");
inStream.close();
String value = "IPMessage\">";
// 从反馈的结果中提取出IP地址
int start = strber.indexOf(value);
int end = strber.indexOf("</span>");
line = strber.substring(start + value.length(), end);
return line;
}
} catch (MalformedURLException e)
{
e.printStackTrace();
} catch (IOException e)
{
e.printStackTrace();
}
return null;
}