zoukankan      html  css  js  c++  java
  • C# 网卡IP(网上资料整理)

    //设置对外访问所使用网卡的IP
    
    string sendingIp = "192.168.0.1";
    
    //设置对外访问所使用的端口
    
    int sendingPort = 5000;
    
    Uri uri = new Uri("http://google.com");
    
    HttpWebRequest wr = (HttpWebRequest)WebRequest.Create(uri);
    
    //获取对外访问的包,并指定使用那个IP(网卡)与端口来发送数据包
    
    ServicePoint sp = ServicePointManager.FindServicePoint(uri);
    
    sp.BindIPEndPointDelegate =
    
        (servicePoint,remoteEp,retryCount) =>
    
             {
    
                 return new IPEndPoint(IPAddress.Parse(sendingIp),sendingPort);
    
             };
    
    //提交请求并获取返回结果
    
    var data = new StreamReader(wr.GetResponse().GetResponseStream()).ReadToEnd();
    //获取多网卡Ip
    NetworkInterface[] NetworkInterfaces = NetworkInterface.GetAllNetworkInterfaces(); foreach (NetworkInterface NetworkIntf in NetworkInterfaces) { IPInterfaceProperties IPInterfaceProperties = NetworkIntf.GetIPProperties(); UnicastIPAddressInformationCollection UnicastIPAddressInformationCollection = IPInterfaceProperties.UnicastAddresses; foreach (UnicastIPAddressInformation UnicastIPAddressInformation in UnicastIPAddressInformationCollection) { if (UnicastIPAddressInformation.Address.AddressFamily == AddressFamily.InterNetwork) { MessageBox.Show(UnicastIPAddressInformation.Address.ToString()); } } }
  • 相关阅读:
    NYOJ 42 一笔画问题
    python raise 使用方法
    五种异常处理机制:默认异常处理、assert与with...as
    都想学
    骆驼祥子
    XSHELL使用技巧
    明朝那些事儿
    百年孤独
    Linux常用命令
    重庆森林-金城武
  • 原文地址:https://www.cnblogs.com/LiMin/p/3478468.html
Copyright © 2011-2022 走看看