Code
/*
 * Created by SharpDevelop.
 * User: Administrator
 * Date: 2008/9/11
 * Time: 下午 03:51
 * 
 */
using System;
using System.Net;
class Test
{
    private static string getIPAddress()
    {
        System.Net.IPAddress addr;
        addr=new System.Net.IPAddress(Dns.GetHostByName(Dns.GetHostName()).AddressList[0].Address);
        return addr.ToString();
    }
    static void Main()
    {

Console.WriteLine(System.Net.Dns.GetHostName());
        Console.WriteLine(getIPAddress());
    }
}

using System;
using System.Net;
using System.Net.Sockets;
using System.Text.RegularExpressions;

namespace Mssc.Services.ConnectionManagement
{

class TestIPAddress 
  {

/**
      * The IPAddresses method obtains the selected server IP address information.
      * It then displays the type of address family supported by the server and its 
      * IP address in standard and byte format.
      **/
    private static void IPAddresses(string server) 
    {
      try 
      {
        System.Text.ASCIIEncoding ASCII = new System.Text.ASCIIEncoding();

// Get server related information.
        IPHostEntry heserver = Dns.GetHostEntry(server);

// Loop on the AddressList
        foreach (IPAddress curAdd in heserver.AddressList) 
        {

// Display the type of address family supported by the server. If the
          // server is IPv6-enabled this value is: InternNetworkV6. If the server
          // is also IPv4-enabled there will be an additional value of InterNetwork.
          Console.WriteLine("AddressFamily: " + curAdd.AddressFamily.ToString());

// Display the ScopeId property in case of IPV6 addresses.
          if(curAdd.AddressFamily.ToString() == ProtocolFamily.InterNetworkV6.ToString())
            Console.WriteLine("Scope Id: " + curAdd.ScopeId.ToString());

// Display the server IP address in the standard format. In 
          // IPv4 the format will be dotted-quad notation, in IPv6 it will be
          // in in colon-hexadecimal notation.
          Console.WriteLine("Address: " + curAdd.ToString());

// Display the server IP address in byte format.
          Console.Write("AddressBytes: ");

Byte[] bytes = curAdd.GetAddressBytes();
          for (int i = 0; i < bytes.Length; i++) 
          {
            Console.Write(bytes[i]);
          }

Console.WriteLine("\r\n");

}

}
      catch (Exception e) 
      {
        Console.WriteLine("[DoResolve] Exception: " + e.ToString());
      }
    }

// This IPAddressAdditionalInfo displays additional server address information.
    private static void IPAddressAdditionalInfo() 
    {
      try 
      {
        // Display the flags that show if the server supports IPv4 or IPv6
        // address schemas.
        Console.WriteLine("\r\nSupportsIPv4: " + Socket.SupportsIPv4);
        Console.WriteLine("SupportsIPv6: " + Socket.SupportsIPv6);

if (Socket.SupportsIPv6)
        {
          // Display the server Any address. This IP address indicates that the server 
          // should listen for client activity on all network interfaces. 
          Console.WriteLine("\r\nIPv6Any: " + IPAddress.IPv6Any.ToString());

// Display the server loopback address. 
          Console.WriteLine("IPv6Loopback: " + IPAddress.IPv6Loopback.ToString());

// Used during autoconfiguration first phase.
          Console.WriteLine("IPv6None: " + IPAddress.IPv6None.ToString());

Console.WriteLine("IsLoopback(IPv6Loopback): " + IPAddress.IsLoopback(IPAddress.IPv6Loopback));
        }
        Console.WriteLine("IsLoopback(Loopback): " + IPAddress.IsLoopback(IPAddress.Loopback));
      }
      catch (Exception e) 
      {
        Console.WriteLine("[IPAddresses] Exception: " + e.ToString());
      }
    }

public static void Main(string[] args) 
    {
      string server = null;

// Define a regular expression to parse user's input.
      // This is a security check. It allows only
      // alphanumeric input string between 2 to 40 character long.
      Regex rex = new Regex(@"^[a-zA-Z]\w{1,39}$");

if (args.Length < 1)
      {
        // If no server name is passed as an argument to this program, use the current 
        // server name as default.
        server = Dns.GetHostName();
        Console.WriteLine("Using current host: " + server);
      }
      else
      {
        server = args[0];
        if (!(rex.Match(server)).Success)
        {
          Console.WriteLine("Input string format not allowed.");
          return;
        }
      }

// Get the list of the addresses associated with the requested server.
      IPAddresses(server);

// Get additonal address information.
      IPAddressAdditionalInfo();
    }

}
}

转载于:https://www.cnblogs.com/Athrun/archive/2008/09/11/1289308.html

.Net FrameWork中的網絡操作相关推荐

  1. java %3cbr%3e字符替换,Java 網絡編程之 (完全總結)

    TCP TCP,傳輸控制協議(Transmission Control Protocol),是面向連接的通信協議.它提供兩台計算機之間的可靠無差錯的數據傳輸.應用程序通過 TCP 進行通訊時,數據源和 ...

  2. 通过 .NET Framework 中的 XPath 和 XSLT API 方便地操作 XML 数据

    本文假设您熟悉 Visual Basic .NET 下载本文的代码: XPathandXSLT.exe (166KB) 摘要 XPath 是一种正在兴起的通用查询语言.通过 XPath,可以在基于 X ...

  3. newff matlab使用例子,matlab神經網絡newff函數的用法

    設[P,T]是訓練樣本,[X,Y]是測試樣本: net=newrb(P,T,err_goal,spread); %建立網絡 q=sim(net,p); e=q-T; plot(p,q); %畫訓練誤差 ...

  4. Entity Framework中的Migration问题

    1.自从用上了Entity Framework(简称EF),妈妈再也不用担心我要写那么复杂的SQL语句了! 这是微软新一代的ORM工具,它能够将数据库的表中的记录映射成为程序中的一个对象,当然也能够将 ...

  5. Zend Framework中,执行自定义sql语句

    Zend Framework中的Zend_Db_Table类可以很好的对数据表实现select,insert,delete等操作.但是有时候还是希望自己运行一些sql语句. ZF当然也是支持的. 一种 ...

  6. BZOJ1001[BeiJing2006]狼抓兔子最小割網絡流

    Description 现在小朋友们最喜欢的"喜羊羊与灰太狼",话说灰太狼抓羊不到,但抓兔子还是比较在行的, 而且现在的兔子还比较笨,它们只有两个窝,现在你做为狼王,面对下面这样一 ...

  7. 在Entity Framework中使用存储过程(一):实现存储过程的自动映射

    之前给自己放了一个比较长的假期,在这期间基本上没怎么来园子逛.很多朋友的留言也没有一一回复,在这里先向大家道个歉.最近一段时间的工作任务是如何将ADO.NET Entity Framework 4.0 ...

  8. .NET(C#) Internals: .NET Framework中已使用的设计模式

    --适合有一定设计模式基础和.NET基础的人阅读. 写在前面 "设计模式"我一向是敬而远之的态度,不会去写这方面的文章,原因有二:第一,要想写好设计模式的文章太难,需要笔者丰富的经 ...

  9. 关于Entity Framework中的Attached报错相关解决方案的总结

    关于Entity Framework中的Attached报错的问题,我这里分为以下几种类型,每种类型我都给出相应的解决方案,希望能给大家带来一些的帮助,当然作为读者的您如果觉得有不同的意见或更好的方法 ...

最新文章

  1. 吴恩达:AI是时候从大数据转向「小数据」了
  2. cocos2d-html5 onEnter init ctor构造函数 ----js特有特性(和c++有一点不一样)
  3. php记录代码执行时间
  4. 面试题之发散思维能力:如何用非常规方法求1+2+···+n
  5. 启动sqlserver_微软的 SQL Server 你学会了吗?
  6. Python3.x:pip命令安装第三方库,超时处理方案
  7. Python中的虚拟环境-virtualenv
  8. swift文档_Swift 正式进入 Windows 平台
  9. Snort规则检测引擎--架构解析
  10. 扫描仪twain驱动是什么_建湖扫描仪卡纸一般多少钱
  11. [转载]Mysql导出表结构及表数据 mysqldump用法
  12. AVR-GCC与AVR单片机C语言开发,[推荐]AVR 单片机与GCC 编程 教程
  13. php传奇发布站,传奇发布网站php源码
  14. via浏览器下载路径_via浏览器
  15. 萝卜青菜各有所爱------console系列详解
  16. 深信服python开发工程师面试经验,深信服软件工程师面试经验
  17. 微信公众平台开发-入门教程
  18. 医德:《大医精诚》和《希波克拉底誓言》
  19. 成熟男人与24岁女孩精彩对白 —非常感动
  20. 中国AI觉醒 阿里王坚:云智能将成为大趋势

热门文章

  1. libxml2中文支持
  2. ES6基础4(数据结构)-学习笔记
  3. 【Numpy学习记录】np.cov详解
  4. tomcat端口被占用-----windows下如何查询某个端口被哪个进程占用以及如何杀死进程
  5. 【搜索引擎Jediael开发笔记3】使用HtmlParser提取网页中的链接
  6. scrapy需要的xpath知识点
  7. 如何将不同类型数据导入Elaticsearch中?
  8. vuex 基本入门和使用(一)
  9. 基于Spring Boot的“课程设计”的设计与实现
  10. php课程 6-20 字符串基础和去除空格和字符串填补函数