Sign In Register

How can we help you today?

Start a new topic
Answered

Get User IP Address

Hi,

we are planning to integrate DB with some external service which requires user IP address to work. Is it possible to get current IP from player?


Best Answer

Hi Marcin,


You can provide the IP Address from the client and send it to the Cloud Code to save on the Gamesparks DB. It is not possible to infer the IP Address from the Cloud Code on it's own.


In Unity this is as simple as:


    

using System.Net;
using System.Net.Sockets;

IPHostEntry host;
string localIP = "";
host = Dns.GetHostEntry(Dns.GetHostName());
        
foreach (IPAddress ip in host.AddressList)
{
             if (ip.AddressFamily == AddressFamily.InterNetwork)
             {
                 localIP = ip.ToString();
                 break;

             }
} 

  


  You can then send this string with any of our requests such as Authentication, Registration or LogEvent. Then in the Cloud Code for these events, save the attribute in a collection, or even the player's privateData.


If you have any other questions let me know.


-Pádraig


Answer

Hi Marcin,


You can provide the IP Address from the client and send it to the Cloud Code to save on the Gamesparks DB. It is not possible to infer the IP Address from the Cloud Code on it's own.


In Unity this is as simple as:


    

using System.Net;
using System.Net.Sockets;

IPHostEntry host;
string localIP = "";
host = Dns.GetHostEntry(Dns.GetHostName());
        
foreach (IPAddress ip in host.AddressList)
{
             if (ip.AddressFamily == AddressFamily.InterNetwork)
             {
                 localIP = ip.ToString();
                 break;

             }
} 

  


  You can then send this string with any of our requests such as Authentication, Registration or LogEvent. Then in the Cloud Code for these events, save the attribute in a collection, or even the player's privateData.


If you have any other questions let me know.


-Pádraig

Cool, thank you, this will help. But for the future that would be great to get that kind of data exactly from cloud code:)

I've double checked and noticed that you solution only returns lokal network IP adress (like 192.168.xxx)

 

Hey Marcin,

There are many ways to get the IP from the client -> http://forum.unity3d.com/threads/get-ip-address.100109/
We do not store the IP on the player-doc as we do not currently use it for anything. However you can get the IP from the client and us it in cloud-code as you wish. You should be careful however, as none of these methods are 100% reliable and are based on ISP rules too.

Sean

 

hi.
i was wondering if it's gamespark's limitation that it cannot have player's ip address. or for security reason they dont provide ip address

Hi Ahsan,


In line with Data Protection conventions, we do not have direct or access, nor do we expose the ip address of users. Apologies for any inconvenience caused. 


Best Regards, Patrick. 

Login to post a comment