• A Way to Save IP Addresses
    4 replies, posted
Hi, I would like to have a way to show the IPs of users that connect to my server in a little TXT file, but I couldn't find any on the interwebs.
There's a lot of ways. However unless you try yourself no one's going to spoon feed it to you.
Make a folder in your data folder called logger Then use [code] local function dologger(ply) local stidsanitized = string.sub( ply:SteamID(), 11, #ply:SteamID() ) if (!file.Exists("logger/"..stidsanitized..".txt", "DATA")) then local playerinfo = { ["uniqueid"] = ply:UniqueID(), ["steamid"] = ply:SteamID(), ["name"] = ply:Name(), ["ip"] = ply:IPAddress(), ["steamid64"] = ply:SteamID64() } local plyinfostr = util.TableToJSON(playerinfo) file.Write("logger/"..stidsanitized..".txt", plyinfostr ) end end hook.Add("PlayerInitialSpawn", "logging", dologger) [/code] Be aware though that this will get VERY large, VERY quickly. [IMG]http://i.gyazo.com/03f3d077839b0fec234a0231bc4e9a92.png[/IMG] @Penguin You clearly underestimate the size of my spoon.
Thank you Lolcats.
[lua] file.CreateDir('logger') local function logIP(ply) local id = ply:UniqueID() local path = "logger/"..id..".txt" local exists = file.Exists(path,"DATA") local method = (exists and file.Append) or file.Write local text = ply:IPAddress() .. ' - ' .. ply:Nick() .. ' - ' .. ply:SteamID() if exists then local ips = string.Explode('\n',file.Read(path,"DATA")) if #ips > 1 and ips[#ips-1] == text then return end end method(path,text..'\n') end hook.Add("PlayerInitialSpawn", "logging", logIP) [/lua] If anything changes then it writes, helps you keep track of which ip belongs to what name and steamid and if any of those change. edit: late
Sorry, you need to Log In to post a reply to this thread.