1

I need the IP of the users in my WebGL build and I tried to run this code to get it, and it work's fine when executed locally on my pc. But when I post the build on itch.io it produces a wierd error. I tried it both on itch.io and our own server and it produces the same error. I also tried uploading an empty WebGL build and that worked fine.

This build has only one script in the scene and that is to get the ip, and that's the script I pasted below the link.

https://badassss.itch.io/test

using UnityEngine;
using System.Net;
using UnityEngine.UI;

public class WebGLGetIP : MonoBehaviour
{
    public Text ips;

    private void Start()
    {
        FetchIPAdresses();
    }

    private void FetchIPAdresses()
    {
        string hostName = Dns.GetHostName();
        IPAddress[] addresses = Dns.GetHostAddresses(hostName);
        Debug.Log($"GetHostAddresses({hostName}) returns:");
        foreach (IPAddress address in addresses)
        {
            string adress = $"    {address}";
            ips.text += "/n" + adress;
        }
    }
}
gman
  • 100,619
  • 31
  • 269
  • 393
anonymous-dev
  • 2,897
  • 9
  • 48
  • 112
  • From the [documentation](https://docs.unity3d.com/Manual/webgl-networking.html): *"everything in the `System.Net` namespace, particularly `System.Net.Sockets` are non-functional in WebGL"* – UnholySheep Oct 20 '19 at 17:50
  • Check this if it helps you https://stackoverflow.com/questions/51975799/how-to-get-ip-address-of-device-in-unity-2018 – Amir Javed Oct 21 '19 at 07:13

1 Answers1

1
string IP = NetworkManager.singleton.networkAddress;