获取本机外网ip地址

package com.ning;

import java.io.BufferedReader;

import java.io.InputStreamReader;

import java.net.URL;

public class Listip {

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

    System.out.println("本机的外网IP是:"

    //+ Listip.getWebIp("http://iframe.ip138.com/ic.asp"));

     //+ Listip.getWebIp("http://www.ip138.com"));

    + Listip.getWebIp("http://1111.ip138.com/ic.asp"));

  }

  public static String getWebIp(String strUrl) {

    try {

      URL url = new URL(strUrl);

      BufferedReader br = new BufferedReader(new InputStreamReader(url.openStream(),"GB2312"));

       String s = "";

       StringBuffer sb = new StringBuffer("");

      String webContent = "";

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

        sb.append(s + "rn");

       }

       br.close();

      webContent = sb.toString();

      int start = webContent.indexOf("[") + 1;

      int end = webContent.indexOf("]");

      System.out.println("webContent=" + webContent);

       System.out.println("start=" + start);

      System.out.println("end=" + end);

       if (start < 0 || end < 0) {

        return null;     

      }

       webContent = webContent.substring(start, end);

       return webContent;

    } catch (Exception e) {

      e.printStackTrace();

      return "error open url:" + strUrl;

    }

}

}

时间: 2024-10-11 00:31:11

获取本机外网ip地址的相关文章

用Linux命令行获取本机外网IP地址

用Linux命令行获取本机外网IP地址 $ curl ifconfig.me$ curl icanhazip.com$ curl ident.me$ curl ipecho.net/plain$ curl whatismyip.akamai.com$ curl tnx.nl/ip$ curl myip.dnsomatic.com$ curl ip.appspot.com$ curl -s checkip.dyndns.org | sed 's/.*IP Address: \([0-9\.]*\)

获取本机外网IP的工具类

ExternalIpAddressFetcher.java package com.tyust.common; import java.io.IOException; import java.io.InputStream; import java.net.HttpURLConnection; import java.net.MalformedURLException; import java.net.URL; import java.util.regex.Matcher; import java

php 通过ip获取所在城市地址信息 获取计算机外网ip

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-

获取本机外网ip和内网ip

获取本机外网ip 1 //获取本机的公网IP 2 public static string GetIP() 3 { 4 string tempip = ""; 5 try 6 { 7 WebRequest request = WebRequest.Create("http://ip.qq.com/"); 8 request.Timeout = 10000; 9 WebResponse response = request.GetResponse(); 10 Stre

关于获得本机外网IP地址的问题

改了个系统中的小功能,显示在线用户的IP地址和MAC地址,用到了这几个方法,记录下. 方法1,获得IP地址: string ipAddress = "": WebRequest wr =WebRequest.Create("http://1212.ip138.com/ic.asp"); Stream s = wr.GetResponse().GetResponseStream(); StreamReader sr = new StreamReader(s, Enco

Linux终端中获取本机外网 IP 的方法

在终端中输入 curl ipinfo.io 或者 curl ifconfig.me 即可通过IP地址检测网站提供的api获得取本机的外网IP,或者以 JSON 格式返回全部结果.

Python获取本机外网IP

1. 打开https://www.baidu.com/ 2. 输入ip, 进行搜索, 获取url http://cn.bing.com/search?q=ip&go=%E6%8F%90%E4%BA%A4&qs=n&form=QBLH&pq=ip&sc=8-2&sp=-1&sk=&cvid=14b93b305cdc4183875411c3d9edf938 3. 查找url返回结果 编写python匹配正则表达式 4. Python完整代码 1

linux 通过命令行获取本机外网IP

curl ifconfig.me curl icanhazip.com curl ident.me curl whatismyip.akamai.com curl tnx.nl/ip curl myip.dnsomatic.com 版权声明:本文为博主原创文章,未经博主允许不得转载.

c#获取外网IP地址的方法

1.如果你是通过路由上网的,可以通过访问ip138之类的地址来获取外网IP 2.如果是通过PPPOE拨号上网的,可以使用以下代码获取IP //获取宽带连接(PPPOE拨号)的IP地址,timeout超时(秒),当宽带未连接或者连接中的时候获取不到IP public static string GetIP_PPPOE(int timeout) { int i = timeout * 2; while (i > 0) { try { NetworkInterface[] nics = Network