惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Cisco Talos Blog
Cisco Talos Blog
V
V2EX
C
Check Point Blog
GbyAI
GbyAI
D
Docker
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
B
Blog RSS Feed
H
Hackread – Cybersecurity News, Data Breaches, AI and More
N
Netflix TechBlog - Medium
T
Troy Hunt's Blog
博客园 - Franky
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
Microsoft Security Blog
Microsoft Security Blog
P
Privacy & Cybersecurity Law Blog
WordPress大学
WordPress大学
The Cloudflare Blog
S
SegmentFault 最新的问题
Latest news
Latest news
Microsoft Azure Blog
Microsoft Azure Blog
P
Proofpoint News Feed
I
InfoQ
博客园 - 【当耐特】
NISL@THU
NISL@THU
A
About on SuperTechFans
T
Tailwind CSS Blog
酷 壳 – CoolShell
酷 壳 – CoolShell
The Hacker News
The Hacker News
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Scott Helme
Scott Helme
雷峰网
雷峰网
C
CXSECURITY Database RSS Feed - CXSecurity.com
Security Latest
Security Latest
V
Vulnerabilities – Threatpost
Security Archives - TechRepublic
Security Archives - TechRepublic
A
Arctic Wolf
Hacker News: Ask HN
Hacker News: Ask HN
N
News and Events Feed by Topic
IT之家
IT之家
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
aimingoo的专栏
aimingoo的专栏
T
Threat Research - Cisco Blogs
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
阮一峰的网络日志
阮一峰的网络日志
SecWiki News
SecWiki News
大猫的无限游戏
大猫的无限游戏
S
Security Affairs
The Register - Security
The Register - Security
www.infosecurity-magazine.com
www.infosecurity-magazine.com
L
LINUX DO - 热门话题
T
Tor Project blog

博客园 - 小柯

Enterprise Library 4.1 Configuration的使用 C#模仿QQ截图功能 asp.net 中 DropDownList 加入可输入功能解决方案 - 小柯 解决SQL Server Management Studio Express为英文的问题 Visual Studio 2008 简体中文正式版下载及序列号(无使用期限限制,正式版) 程序人生--一个程序员对学弟学妹建议(转) .NET 换肤软件 IrisSkin 2.0 破解版下载及多款皮肤下载 (转)JavaScript 弹出窗口总结 (转)JavaScript常用判断函数(正则表达式版) C#中常用的经典文件操作方法 反编译工具Reflector下载(集成两个常用.net插件,FileGenerator和FileDisassembler) C#遍历指定目录的递归(完美改进版+完整程序源码) C#遍历目录树的递归 在ASP.NET中自动给URL加上超链接 ASP.NET 中 Cookie 的基本知识 ASP.NET2.0统计图表(转) (转)了解你的兵器---VS2005 快捷键 Asp.Net Ajax系列(二) 局部页面呈现(Partial-Page Rendering) Asp.net Ajax 系列(一) ----------用了再说
ASP.NET获取IP及电脑名等信息的简单方法+通用类文件源码
小柯 · 2007-01-15 · via 博客园 - 小柯

1. 在ASP.NET 中专用属性:
获取服务器电脑名:Page.Server.ManchineName
获取用户信息:Page.User
获取客户端电脑名:Page.Request.UserHostName
获取客户端电脑IP:Page.Request.UserHostAddress

2. 在网络编程中的通用方法:
获取当前电脑名:static System.Net.Dns.GetHostName()
根据电脑名取出全部IP地址:static System.Net.Dns.Resolve(电脑名).AddressList
也可根据IP地址取出电脑名:static System.Net.Dns.Resolve(IP地址).HostName

3. 系统环境类的通用属性:
当前电脑名:static System.Environment.MachineName
当前电脑所属网域:static System.Environment.UserDomainName
当前电脑用户:static System.Environment.UserName

一个获取本机内网和外网IP的公用类 

using System;
using System.IO;
using System.Net;
using System.Text;
using System.Text.RegularExpressions;
namespace ipip
{
 /// <summary>
 /// Class1 的摘要说明。
 /// 获取本机上网IP和内网IP
 /// </summary>
 public class Class1
 {
 
  private string strgetIP;
  
  public Class1()
  {
   //
  
  netIP();
  getIP(); 
  }
  
  
   
  

  public string renetIP()
  {return netIP();}//返回网络IP

  public string regetIP()
  {return strgetIP;}//返回内网IP

  
  static string netIP()
  {
   Uri uri = new Uri("http://www.ikaka.com/ip/index.asp");//查本机网络IP的网页
   HttpWebRequest req = (HttpWebRequest)WebRequest.Create(uri);
   req.Method = "POST";
   req.ContentType = "application/x-www-form-urlencoded";
   req.ContentLength = 0;
   req.CookieContainer = new CookieContainer();
   req.GetRequestStream().Write(new byte [0], 0, 0);
   HttpWebResponse res = (HttpWebResponse)(req.GetResponse());
   StreamReader rs = new StreamReader(res.GetResponseStream(), Encoding.GetEncoding("GB18030"));
   string s = rs.ReadToEnd();
   rs.Close();
   req.Abort();
   res.Close();
   Match m = Regex.Match(s, @"IP:\[(?<IP>[0-9\.]*)\]");
   if (m.Success) return m.Groups["IP"].Value;
   string strnetIP= string.Empty;
   return strnetIP;
  }

  public string getIP()//注意与static 的区别
  {
   System.Net.IPAddress[] addressList = Dns.GetHostByName(Dns.GetHostName()).AddressList;//获取本机内网IP
  

    strgetIP = addressList[0].ToString();
    return strgetIP;
   
  }

  
 
 }

}