Pergunta

I'm designing a system for mobile devices that can be assigned only to one job at a time. So I need to be able to know which mobile device is being used by accessing it's own unique static IP address or its device ID. I don't want to assign an ID myself for every machine that comes in which is why a static IP would work great.

However, in trying to retrieve the client ip address I'm retrieving the wireless router's ip or some other ip which is not the mobile device's ip.

I want to store that ip in a table and control which jobs are assigned to it. How can I accomplish this?

I've tried the following but I'm getting the wireless ip:

   var hostEntry = Dns.GetHostEntry(Dns.GetHostName());
    var ip = (
               from addr in hostEntry.AddressList
               where addr.AddressFamily.ToString() == "InterNetwork"
               select addr.ToString()
        ).FirstOrDefault();

I'd rather not set a cookie if there exists a better alternative.

TIA!

Foi útil?

Solução 5

I got my answer from this website.

I passed Request.ServerVariables["REMOTE_ADDR"] to the function in the above site and got the client computer name which I will use to identify each machine. IP's can change but rarely will a computer name change. Thanks for you input.

Outras dicas

As you are using a handset to access your webpage your options for unique IDs are more limited (as compared to a native mobile app). I have built over 100 mobile (native) systems in the past 13 years, but have never created a mobile web app so forgive me if I "miss the target" a bit.

If you are looking for either a MAC address, GUID, or the handset's IMEI (or some other unique value) it would seem to me a reasonable place to start would be with some JavaScript - as this query needs to execute on the handset, and the value needs to be passed in as part of the GET or POST invocation. As an alternative you can check if the new HTML5 supports any kind of direct "query" ability to its host?

I would stay away from the IP address if I were you as this can change quickly (user is walking up to a Starbucks and accessing server via cellular then picks up the Wi-Fi while ordering coffee), then goes up the elevator and is on the office network.

Though, you may wish to avoid cookies it’s still a valid approach (if the unique value needs to persist across sessions). Also, if values do not need to persist across sessions simply create the GUID / UUID as part of the server's initial response (included in all subsequent session calls from handset). Anything cookie related has the potential problem of the user deleting cookies, and thus making the client appear as a new user - depending on your requirements.

Lastly, create a GUID yourself (JavaScript) and submit it as part of the request (obviously this won't persist across sessions).

you should better describe your environment. It looks like you are running an IIS with .net code. If you are looking for getting the clients IP address in PHP (if you are running PHP on IIS too), you can use the answer here How to get the client IP address in PHP?: Use $_SERVER['HTTP_X_FORWARDED_FOR'] and also save the $_SERVER['REMOTE_ADDR']

If you are running IIS with .NET only (no PHP) you may use the answer of Getting client values of IIS Server Variables in Load Balanced Environment: HttpContext.Current.Request.ServerVariables.Item("REMOTE_HOST") and Request.ServerVariables("X-Forwarded-For")

regards

Josef

You could use the MAC Address. You can retrieve this using the .Net Compact Framework.

You can use GetDeviceUniqueID for this. See:

http://blogs.msdn.com/b/windowsmobile/archive/2006/01/09/510997.aspx

... unless you're trying to get a unique device ID for a device making a web request through IE mobile.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top