程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 數據庫知識 >> SqlServer數據庫 >> 關於SqlServer >> SQL與IP相關的常見問題

SQL與IP相關的常見問題

編輯:關於SqlServer

1:得到客戶端的IP地址
/************* IP **************/
declare @ip varchar(20),@hst varchar(20),@sql varchar(100)
declare @str varchar(100)
set @str='PING '+Host_Name()
create table #tmp(aa varchar(200))
insert #tmp exec master..xp_cmdshell @str
select top 1 @ip = replace(left(aa,charindex(':',aa)-1),'Reply from ','')
from #tmp where aa like 'reply from %:%'
drop table #tmp
select @ip


2:得到網卡的物理地址
create table #tb(re varchar(255))
insert into #tb exec master..xp_cmdshell 'ipconfig /all'

select 網卡物理地址=substring(re,charindex(':',re)+1,255) from #tb where re like '%Physical Address. . . . . . . . . :%'

drop table #tb

3: 將IP地址段轉成每三位用點號分開
create function getIP(@a varchar(15))
returns varchar(15)
As
begin
declare @s varchar(15)
set @s = ''
while charindex('.',@a) > 0
begin
set @s = @s + right('000' + left(@a,charindex('.',@a)),4)
set @a = right(@a,len(@a)-charindex('.',@a))
end
set @s = @s + right('000' + @a,3)
return @s
end

/*
Select dbo.getIP('202.1.110.2')
---------------
202.001.110.002

(所影響的行數為 1 行)
*/
--drop function getIP


<
  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved