博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
C# 网卡IP(网上资料整理)
阅读量:7220 次
发布时间:2019-06-29

本文共 1386 字,大约阅读时间需要 4 分钟。

//设置对外访问所使用网卡的IPstring 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());                    }                }            }

 

转载于:https://www.cnblogs.com/LiMin/p/3478468.html

你可能感兴趣的文章
redis:Sentinel高可用方案
查看>>
Linux 系统故障排除
查看>>
我的友情链接
查看>>
Mysql汉子转拼音
查看>>
设置MySQL数据库超时
查看>>
一致性hash算法
查看>>
lua + redis 的去重队列
查看>>
web负载均衡(ipvsadm)(未成)
查看>>
抓取存储quota超过80%的users
查看>>
C语言经典算法100例
查看>>
速成CAD版本转换的教程
查看>>
CAD文件图纸过大,该怎么解决?
查看>>
Spring aop 切不进去原因。。
查看>>
PHP获取客户端IP
查看>>
php开发APP接口-封装通信接口改进版
查看>>
Android系统性能演变历程
查看>>
OSChina 周三乱弹 —— 打醒精神去瞌睡
查看>>
SSH 密钥登录linux
查看>>
你必须掌握的 21 个 Java 核心技术!
查看>>
告诉你WHT中文站是什么?
查看>>