SQL中取IP位址

2021-04-12 23:45:32 字數 2572 閱讀 3113

該方法查自網上,實際運用過程中,可根據實際情況修改

以下是根據spid獲取ipaddress

create proc sp_get_hostip (@spid int = null) as

set nocount on

declare @host varchar(100)

declare @ip varchar(15)

declare @cmd varchar(200)

declare @temp varchar(255)

create table #ip(iptext varchar(255))

if @spid is null select @host = host_name()

else

select @host = max(hostname)

from master..sysprocesses

where spid = @spid

if @host is not null

begin

set @cmd = 'ping -n 1 ' + @host

insert #ip exec master..xp_cmdshell @cmd

select @ip = isnull(substring(iptext,(charindex('[',iptext)+1),

(charindex(']',iptext)-(charindex('[',iptext)+1))),'')

from #ip

where charindex('[',iptext)>0

enddrop table #ip

select nullif(rtrim(@host),'') as 'hostname',

rtrim(@ip) as 'ip_address'

return

下邊是另一種實現方法,思想類似

create procedure dbo.sp_spidtoip @spid int

as -- spid to mac

-- lj

declare @mac as varchar(12)

select @mac = net_address from master..sysprocesses where spid = @spid

-- mac to ip

declare @macdisplay as varchar(18)

declare @ip as varchar(15)

create table #temp (output varchar(255) null)

set nocount on

insert into #temp exec master..xp_cmdshell 'arp -a'

if @@error<>0

begin

raiserror ('the level for job_id:%d should be between %d and %d.', 16, 1)

--rollback transaction

end

select @macdisplay = left(@mac, 2) + '-' + substring(@mac, 3, 2) + '-' + substring(@mac, 5, 2) + '-' + substring(@mac, 7, 2) + '-' + substring(@mac, 9, 2) + '-' + substring(@mac, 11, 2) select @ip = substring(output, 3, 15) from #temp where output like '%' + @macdisplay + '%'

-- resolve the ip

--declare @cmd as varchar(100)

--select @cmd = 'master..xp_cmdshell "ping -a ' + @ip + '"'

--exec (@cmd)

drop table #temp

set nocount off

簡單的返回本機ip,不能封成函式,因為函式內無法訪問臨時表

create proc sp_get_hostip(@ip varchar(15) output)

asdeclare @cmd varchar(200);

create table #iptemp(iptext varchar(255));

set @cmd = 'ping -n 1 ' + host_name();

insert #iptemp exec master..xp_cmdshell @cmd;

select @ip = isnull(substring(iptext,(charindex('[',iptext)+1),(charindex(']',iptext)-(charindex('[',iptext)+1))),'') from #iptemp where charindex('[',iptext)>0;

drop table #iptemp;

if ( @ip <> '' )

return 1;

else

return 0;

取IP位址所在城市

using system using system.collections.generic using system.linq using system.web using system.io using system.text using system.text.regularexpression...

爬取免費的IP位址

要是有錢買好的ip 誰還爬ip位址啊,有錢人請繞路 資料是存在於mogodb資料庫,開了三個執行緒,我覺得夠了 import requests from bs4 import beautifulsoup import time import pymongo import random import ...

C 取真實IP位址及分析

說一哈,我也是轉來的,不是想騙pv,方便自己查而已 目前網上流行的所謂 取真實ip位址 的方法,都有bug,沒有考慮到多層透明 的情況。多數 類似 事實上,上面的 只試用與使用者只使用了1層 如果使用者有2層,3層http x forwarded for 的值是 本機真實ip,1層 ip,2層 ip...