How can I get the ping from the master server?

I have a complicated code, however I call

GUILayout.Label("Ping : " + Network.GetAveragePing(Network.player) + " ms");

but unfortunately it debug me -1, then trying

Debug.Log(Network.player);

it also gives me -1

So, how can I get the ping between my client computer and a host or a master server??

Use something like this-

var masterPing : Ping = new Ping("0.0.0.0");

function GetMasterServerPing()
{
    masterPing = new Ping(MasterServer.ipAddress);
}

function OnGUI()
{
    if(masterPing.isDone)
    {
        GUILayout.Label("Master Server Ping: " + masterPing.time " + ms");
    } else {
        GUILayout.Label("Master Server Ping unknown- still retrieving!");
    }
}

If you are not yet connected to a server, or have not hosted a game, Network.Player will always return -1 because the ‘player’ is invalid! In the same way, even when you are connected, using Network.GetAveragePing on yourself will always return 0 (or close to 0) because there is no network lag between yourself and yourself! Otherwise, use Ping in the same way using NetworkPlayer.ipAddress instead of MasterServer.ipAddress, with whichever NetworkPlayer you are referring to.