c 判斷正確的ip位址格式與轉換

2021-06-20 16:56:17 字數 927 閱讀 6252

c#判斷正確的ip位址格式。

判斷ip位址是否正確,直接用.net現成的類,方法如下

string ipstr="192.168.222.333";

ipaddress ip;

if(ipaddress.tryparse(ipstr,out ip))

else

c# ip位址與整數之間轉換的具體方法

ip位址與整數之間的轉換

1、ip位址轉換為整數

每段數字 相對應的二進位制數

10 00001010

0 00000000

3 00000011

193 11000001

c#**:www.jbxue.com

public static long iptoint(string ip)

; string items = ip.split(separator);

return long.parse(items[0]) << 24

| long.parse(items[1]) << 16

| long.parse(items[2]) << 8

| long.parse(items[3]);

}

2、整數轉換為ip位址

舉例,整數:167773121

二進位制表示形式為:00001010 00000000 00000011 11000001

分割成四段:00001010,00001010,00000011,11000001,分別轉換為整數後加上「.」就得到了10.0.3.193。

c#**:

public static string inttoip(long ipint)

轉換IP位址格式

非原創 只是學習而已。後記 define nipquad addr unsigned char addr 0 unsigned char addr 1 unsigned char addr 2 unsigned char addr 3 define nipquad fmt u.u.u.u 轉換ip位...

正確的IP位址

簡介 ip位址 英語 internet protocol address 是一種在internet上的給主機編址的方式,也稱為網際協議位址。ip位址是ip協議提供的一種統一的位址格式,它為網際網路上的每乙個網路和每一台主機分配乙個邏輯位址,以此來遮蔽實體地址的差異。常見的ip位址,分為ipv4與ip...

IP包頭格式與IP位址分類

version 版本,ihl ip頭資料長度,type ofservice 服務的形式,total length 資料總長度 identification 身份,flag 標籤,fragment offaet 偏移量,time of live 存活時間,protocol 協議形式,header ch...