请问怎么用php来实现去获取某个用户的ip然后存到自己的数据库mysql中,给代码参考看看,谢谢

请问怎么用php来实现去获取某个用户的ip然后存到自己的数据库mysql中,给代码参考看看,谢谢,第1张

1.改表法。可能是你的帐号不允许从远程登陆,只能在localhost。这个时候只要在localhost的那台电脑,登入mysql后,更改

"mysql"

数据库

"user"

表里的

"host"

字段,把"localhost"改称"%",即可。

mysql

-u

root

-pvmwaremysql>use

mysqlmysql>update

user

set

host

=

'%'

where

user

=

'root'mysql>select

host,

user

from

user

2.授权法。例如,你想用户myuser使用密码mypassword通过ip地址连接到mysql服务器,使用:

grant

all

privileges

on

*.*

to

'myuser'@'%'

identified

by

'mypassword'

with

grant

option

如果你想允许用户myuser从ip为192.168.1.3的主机连接到mysql服务器,并使用mypassword作为密码

grant

all

privileges

on

*.*

to

'myuser'@'192.168.1.3'

identified

by

'mypassword'

with

grant

option

1,我不知道你用的什么数据库,反正我用的mysql,本地的数据库地址都是localhost或者127.0.0.1

2

2,你也可以查看一下,右击数据库有个连接属性如图,点开可以看到主机名或ip地址这一项,希望帮到你

所有连接本机的: *** 作的数据库名,计算机名,用户名,网卡物理地址,IP地址,程序名--邹建2003.11(引用请保留此信息)--*//*--调用示例--显示所有本机的连接信息exec p_getlinkinfo--显示所有本机的连接信息,包含ip地址exec p_getlinkinfo @includeip=1--显示连接指定数据库的信息exec p_getlinkinfo '客户资料'--*/createprocp_getlinkinfo@dbnamesysname=null,--要查询的数据库名,默认查询所有数据库的连接信息@includeipbit=0--是否显示IP地址,因为查询IP地址比较费时,所以增加此控制asdeclare@dbidintset@dbid=db_id(@dbname)createtable#tb(idintidentity(1,1),dbname sysname,hostnamenchar(128),loginnamenchar(128),net_addressnchar(12),net_ipnvarchar(15),prog_namenchar(128))insertinto#tb(hostname,dbname,net_address,loginname,prog_name)selectdistincthostname,db_name(dbid),net_address,loginame,program_namefrommaster..sysprocesseswherehostname<''and(@dbidisnullordbid=@dbid)if@includeip=0gotolb_show--如果不显示IP地址,就直接显示declare@sqlvarchar(500),@hostnamenchar(128),@idintcreatetable#ip(hostnamenchar(128),avarchar(200))declaretbcursorlocalforselectdistincthostnamefrom#tbopentbfetchnextfromtbinto@hostnamewhile@@fetch_status=0beginset@sql='ping'+@hostname+'-a -n 1 -l 1'insert#ip(a)execmaster..xp_cmdshell@sqlupdate#ipsethostname=@hostnamewherehostnameisnullfetchnextfromtbinto@hostnameendupdate#tbsetnet_ip=left(a,patindex('%:%',a)-1)from#tb ainnerjoin(selecthostname,a=substring(a,patindex('Ping statistics for %:%',a)+20,20)from#ipwherealike'Ping statistics for %:%') bona.hostname=b.hostnamelb_show:selectid,数据库名=dbname,客户机名=hostname,用户名=loginname,网卡物理地址=net_address,IP地址=net_ip,应用程序名称=prog_namefrom#tbgo------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------(有用的查询)


欢迎分享,转载请注明来源:内存溢出

原文地址: https://www.outofmemory.cn/sjk/6644063.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-03-26
下一篇 2023-03-26

发表评论

登录后才能评论

评论列表(0条)

保存