--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)
asbegin
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))
endset @s = @s + right('000' + @a,3)
return @s
end/*
select dbo.getip('202.1.110.2')
---------------
202.001.110.002
(所影響的行數為 1 行)
*/--drop function getip
linux 得到 客戶端 ip 和 port
在socket程式設計中,伺服器端accept 等待乙個客戶端的連線,當連線成功後,accept拷貝客戶端的位址資訊到sin addr裡面,我們如何從sin addr取得此客戶端的ip位址和埠號呢?實際上,當sockaddr in.sin family af inet時,sockaddr socka...
PHP下得到客戶端ip的方法
getenv gets the value of an environment variable stringgetenv string varname returns the value of the environment variable varname,or false on an erro...
PHP下得到客戶端IP的方法
php下得到客戶端ip的方法 2007 04 19 10 53 但是當web伺服器api是asapi iis 的時候,getenv函式是不起作用的。這種情況下你如果用getenv來取得使用者客戶端ip的話,得到的將是錯誤的ip位址。getenv gets the value of an enviro...