C#的IPAddress IPEndPoint


以前覺得什么都能記住 翻一遍書就能去考試了,現在回過頭來想一些東西,突然有種模糊的陌生感,應了那句好記性不如爛筆頭。做筆記終歸是利大於弊的。麻煩一點但是卻受用。

突然想從頭開始,看一些過去的書,補一些小筆記。

System.Net下的IPAddress IPEndPoint

 

 1     void Start () {
 2         //IPAddress(Byte[])    新實例初始化 IPAddress 類地址指定為 Byte 數組。;
 3         IPAddress ipAddress1 = new IPAddress(new byte[] { 151, 33, 86, 50 }); 
 4         //IPAddress(Int64)    新實例初始化 IPAddress 類地址指定為 Int64。
 5         IPAddress ipAddress2 = new IPAddress(0x2414188f);
 6         //Parse(String)     IP 地址將字符串轉換為 IPAddress 實例
 7         IPAddress ipAddress3 = IPAddress.Parse("192.168.100.9");
 8         Debug.Log("ip1="+ipAddress1+"/ip2="+ipAddress2+"/ip3="+ipAddress3);
 9 
10         //IPEndPoint 表示主機地址和端口信息。
11         IPEndPoint ipEndPoint = new IPEndPoint(ipAddress1,8899);
12         Debug.Log("IP="+ipEndPoint.Address+"/Port="+ipEndPoint.Port);
13 
14         IPAddress[] ips = Dns.GetHostEntry("www.baidu.com").AddressList;
15         foreach (IPAddress ip in ips)
16         {
17             Debug.Log("baidu ip="+ip);
18         }
19         ips = Dns.GetHostAddresses("www.cctv.com");
20         foreach (IPAddress ip in ips)
21         {
22             Debug.Log("cctv ip=" + ip);
23         }
24     }

 

//output

IPAddress 類,提供 Internet 協議 (IP) 地址>>> https://msdn.microsoft.com/zh-cn/library/system.net.ipaddress%28v=vs.110%29.aspx

IPEndPoint 類 ,將網絡端點表示為 IP 地址和端口號>>> https://msdn.microsoft.com/zh-cn/library/system.net.ipendpoint%28v=vs.110%29.aspx


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM