獲取客戶端ip後,把ip段換成數字比較

2021-06-10 19:05:39 字數 2214 閱讀 2556

需求:如果ip表裡存在客戶端訪問的ip,則不讓他訪問。

操作:第一步,獲取客戶端ip

通過已下方法:

}第二步:把獲取的ip段還成數字(把每一段ip都*255,一段三個,二段兩個,三段乙個,四段無,然後把每段得出的值相加,變成乙個數後比較),把已存庫里ip也同樣方                      法換成數字,然後兩個數字進行對比。

下面sql是模仿獲取10.12.6.89來換成數字,通過 view_ca_ip_restrict 檢視去ca_ip_restrict表中查詢,

select * from view_ca_ip_restrict t where to_number(substr('10.12.6.89', 0, instr('10.12.6.89', '.') - 1) * 255 * 255 * 255 +  to_number(substr(substr('10.12.6.89', instr('10.12.6.89', '.', 1, 1) + 1), 0, instr(substr('10.12.6.89', instr('10.12.6.89', '.', 1, 1) + 1), '.') - 1)) * 255 * 255 +  to_number(substr(substr('10.12.6.89', instr('10.12.6.89', '.', 1, 2) + 1), 0, instr(substr('10.12.6.89', instr('10.12.6.89', '.', 1, 2) + 1), '.') - 1)) * 255 + to_number(substr('10.12.6.89', instr('10.12.6.89', '.', 1, 3) + 1))) between t.startip and t.endip

檢視**:

create or replace view view_ca_ip_restrict as   

select to_number(substr(start_ip, 0, instr(start_ip, '.') - 1)) * 255 * 255 * 255 +

to_number(substr(substr(start_ip,

instr(start_ip, '.', 1, 1) + 1),

0,instr(substr(start_ip,

instr(start_ip, '.', 1, 1) + 1),

'.') - 1)) * 255 * 255 +

to_number(substr(substr(start_ip,

instr(start_ip, '.', 1, 2) + 1),

0,instr(substr(start_ip,

instr(start_ip, '.', 1, 2) + 1),

'.') - 1)) * 255 +

to_number(substr(start_ip,

instr(start_ip, '.', 1, 3) + 1)) as startip,

to_number(substr(end_ip, 0, instr(end_ip, '.') - 1)) * 255 * 255 * 255 +

to_number(substr(substr(end_ip,

instr(end_ip, '.', 1, 1) + 1),

0,instr(substr(end_ip,

instr(end_ip, '.', 1, 1) + 1),

'.') - 1)) * 255 * 255 +

to_number(substr(substr(end_ip,

instr(end_ip, '.', 1, 2) + 1),

0,instr(substr(end_ip,

instr(end_ip, '.', 1, 2) + 1),

'.') - 1)) * 255 +

to_number(substr(end_ip, instr(end_ip, '.', 1, 3) + 1)) as endip

from ca_ip_restrict

獲取客戶端ip

1.統計訪問者ip位址 2.設定黑名單,黑名單的使用者不可以訪問聊天室。內容提要 這種情況下同樣透露了客戶端是使用了 伺服器 但編造了乙個虛假的隨機ip 220.4.251.159 代替客戶端的真實 ip來欺騙它 獲取客戶端 ip其實不是個簡單的活兒 因為存在 ip欺騙 和 問題 所以獲取客戶端的 ...

獲取客戶端IP位址

title generating test data author wufeng4552 date 2009 09 23 10 34 02 功能 獲客戶 ip位址 if object id getclientip isnot null drop proc getclientip go create ...

客戶端獲取IP位址

string ip request.getheader x forwarded for string regex 2 0 4 d 25 0 5 01 d d?2 0 4 d 25 0 5 01 d d?if ip null ip.length 0 ip.equalsignorecase locali...