首页 > 开发 > 综合 > 正文

通过外部网站返回得到内网外部IP

2024-07-21 02:29:46
字体:
来源:转载
供稿:网友

商业源码热门下载www.html.org.cn

static string getip()
{
    uri             uri = new uri("http://www.163.com");
    system.net.httpwebrequest  req = (system.net.httpwebrequest)system.net.webrequest.create(uri);
    req.method          = "post";
    req.contenttype     = "application/x-www-form-urlencoded";
    req.contentlength   = 0;
    req.cookiecontainer = new system.net.cookiecontainer();
    req.getrequeststream().write(new byte [0], 0, 0);
    system.net.httpwebresponse res = (system.net.httpwebresponse)(req.getresponse());
    streamreader    rs  = new streamreader(res.getresponsestream(), system.text.encoding.getencoding("gb18030"));
    string          s   = rs.readtoend();
    rs.close();
    req.abort();
    res.close();
    system.text.regularexpressions.match m = system.text.regularexpressions.regex.match(s, @"ip:/[(?<ip>[0-9/.]*)/]");
    if (m.success) return m.groups["ip"].value;
    return string.empty;
}
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表