How to get ip from player?

I need to ban player, i have idea to get player ip, and create list with banned players, if list contain player ip his get disconnected, but i idk how to get player ip, have only client id, in documentation i find nothing, in google too, do something know way to get player ip?

#if UNITY_SERVER || UNITY_EDITOR
using System.Collections.Generic;
using UnityEngine;
using Unity.Netcode;

public class BanManager : MonoBehaviour
{
    public static BanManager main;
    public List<string> bannedIps;
    public void Awake()
    {
        main = this;
    }
    public void Start()
    {
        NetworkManager.Singleton.ConnectionApprovalCallback = ApprovalConnectionForBanCheck;
    }
    public static void BanPlayerIp(ulong clientId)
    {
        main.bannedIps.Add("127.0.0.1"); // i idk how to get ip, then this i add local ip
        NetworkManager.Singleton.DisconnectClient(clientId);
    }
    private void ApprovalConnectionForBanCheck(NetworkManager.ConnectionApprovalRequest request, NetworkManager.ConnectionApprovalResponse response)
    {
        string cachedIp = "127.0.0.1"; // i idk how to get ip, for example just use local ip
        bool approved = true;
        foreach (string s in bannedIps)
        {
            if(s == cachedIp)
            {
                approved = false;
            }
        }
        response.Approved = approved;
        response.Pending = false;
    }

}
#endif

I believe most players in the world connect via a dynamic IP address which means they can easily get another address and you potentially ban someone else.

You would want to use the Authentication Service then you can just ban the Player ID linked to their accounts

2 Likes

Yes, most player uses dynamic IP address, but dynamic ip address donā€™t changes every day, heā€™s changes every 7-14 days (i idk how days, but approximately is 7-14 days), itā€™s have temporarly effeciency

Netcode by default donā€™t provide player auth id, i need manually provide from client in rpc, but i include decompile my game, cheater, when decompile game and change it, can replace idā€™s, generate always new random or replace manually it, all information provided in rpc can be replaced, if cheater cannot overrides methodā€™s i can just push bytes from HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Cryptography (DWORD parametr ā€œMachineGuidā€) and ban it by hardware, but, iā€™m earler say, cheater can replace values, values provide by unity netcode and donā€™t get aviablity replaced are ip and clientId (get changing by re-join on the server), but i provide playerId, not for ban, this exist for getting saves, i can delete saves, but if cheater replace all variables, i have only playerId with his saves and ip (ip iā€™m need to got, i already idk how to get it), you can say ā€˜Use Il2CPPā€™, but with il2cpp cheater can override methods with harmony or something of that, i idk how its works in Il2CPP, but iā€™m sure, bypasses exists

Generally speaking if a solution doesnā€™t solve the problem it is a less than optimal solution. You are describing a case where you want to ban an annoying player and he only has to be smart enough to get a new IP address or use a VPN.

It is a poor solution to your problem.

Cheaters often uses free vpn, free vpn with restrictions, such a ā€˜Temporarly testing using for 24 hoursā€™ or ā€˜10 GB Free Vpn, Next GBā€™s Payā€™, heā€™s create new accounts, this creating can be for a long time, for change ip addres, such a pull out and insert the internet cable, this can use lot of time, player often is lazy, his like just change player id and player, and, maybe cheater donā€™t install vpn? Maybe his toooo lazy to install it, cheater can be stupid and donā€™t know about vpn, or donā€™t remember it, ip banning uses on most games, and, i just need to get ip, all solutions contains alternatives solutions or unprofitability reply like ā€˜Player Can Use Vpnā€™ or ā€˜Ip often dynamic and itā€™s changeā€™, i just need valid replyā€™s

Ok tell you what check for the IP address and add it to a banned list. :slight_smile:

If you know way how to get ip from player, please say it

Thereā€™s a free Unity Service for that, have you had a look at it? it would solve your problem as Evil-Otaku mentioned

EDIT: sorry, I originally wrote ā€œCerestormā€ but the answer was from Evil-Otaku

That was Evil-Otaku :slight_smile: It might be useful to have the IP passed in on client approval for those not wanting to use an authentication service. Is there a good reason for not including it?

2 Likes

I mean if i connect this unity service, i donā€™t get from NetworkClient, OnClientConnected callback args or something of that, i need to provide it manually from rpc, but, cheaters with harmony or something of that can override methods, he can rewrite method to send fake player id, but cheater cannot rewrite clientId, getted from ServerRpcParams or OnClientConnected callback args, in UNet i can get player ip without providing ip from rpc by same player

ConnectionApprovalRequest donā€™t provide player ip, NetworkClient getted by ConnectedClients dictionary too

I invented method, heā€™s stupid, but itā€™s work, and something different unsuitable for me, i use additionally other network library (Mirror), and first connect player to mirror server. When player connect to mirror server, i get ip (I know how to get ip from mirror) and reject connection to netcode (main) server, you can say ā€˜Cheater can rewrite method and directly connect to netcode serverā€™, but, i create ā€˜token listā€™, contain 25 random number from 1 to 9 converted to string, if player connect to mirror server, token create, add to token list, provide to player by rpc sending and send to netcode server, netcode server add this token to token list too, if player connect to netcode server, before spawning player need provide token by rpc, when token provided, netcode server search this token in list, if token doesnā€™t finded, netcode server just kicking player, else netcode server spawn player, i change thread status with ā€˜resolvedā€™ (i answered myself lol)

I know, it was more a question to the gallery. :smile:

That sounds like a painful workaround, it might be worth creating a feature request on the NGO github for visibility on the client IP. Maybe first we can trouble @simon-lemay-unity and ask if he thinks itā€™s something that realistically would be added to the NGO Unity Transport wrapper.

It would indeed make a great feature request for the Unity Transport wrapper. The low level transport package already exposes this information so it would be pretty easy to expose it through the NGO wrapper.

2 Likes