ประโยคที่ง่ายที่สุดคือการใช้สิ่งต่อไปนี้:
ip = request.serverVariables ("remote_addr")
Response.write (IP)
อย่างไรก็ตามวิธีนี้ไม่ถูกต้องสำหรับเซิร์ฟเวอร์พร็อกซีในการเข้าถึงอินเทอร์เน็ตดังนั้นวิธีที่ครอบคลุมมากขึ้นคือการใช้วิธีการต่อไปนี้:
การคัดลอกรหัสมีดังนี้:
<%PrivateFunctionGetIp ()
dimstripaddr
ifrequest.serverVariables ("http_x_forwarded_for") = "" orinstr (request.serverVariables ("http_x_forwarded_for"), "ไม่ทราบ")> 0 จากนั้น
stripaddr = request.serverVariables ("remote_addr")
elseifinstr (request.serverVariables ("http_x_forwarded_for"), ",", ",")> 0 แล้ว
stripaddr = mid (request.serverVariables ("http_x_forwarded_for"), 1, instr (request.serverVariables ("http_x_forwarded_for"), ",")-1)
elseifinstr (request.serverVariables ("http_x_forwarded_for"), ";")> 0 แล้ว
stripaddr = mid (request.serverVariables ("http_x_forwarded_for"), 1, instr (request.serverVariables ("http_x_forwarded_for"), ";")-1)
อื่น
stripaddr = request.serverVariables ("http_x_forwarded_for")
endif
getip = trim (mid (stripaddr, 1,30))
endfunction
ip = getip ()
Response.write (IP)
-