您现在的位置是:网站首页> 编程资料编程资料
可以获取客户端的IP地址的sql语句_MsSql_
2023-05-26
351人已围观
简介 可以获取客户端的IP地址的sql语句_MsSql_
--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
go
--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
/************* 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
go
--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
相关内容
- SQL 导入导出Excel数据的语句_MsSql_
- SQL CONVERT转化函数使用方法小结_MsSql_
- MMC提示不能打开文件SQLServerEnterpriseManager.MSC的解决方法_MsSql_
- sqlserver 错误602,未能在sysindexes中找到数据库 的解决办法_MsSql_
- SQL 超时解决方案 有时并不是设置问题_MsSql_
- 分页存储过程(三)在sqlserver中打造更加准确的分页结果_MsSql_
- 分页存储过程(二)在sqlserver中返回更加准确的分页结果_MsSql_
- SQLServer 使用ADSI执行分布式查询ActiveDorectory对象_MsSql_
- sqlserver 支持定位当前页,自定义排序的分页SQL(拒绝动态SQL)_MsSql_
- SQL Server 分页查询存储过程代码_MsSql_