1

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!

Eric
  • 7,930
  • 17
  • 96
  • 128

5 Answers5

1

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).

BonanzaDriver
  • 6,411
  • 5
  • 32
  • 35
1

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

Community
  • 1
  • 1
josef
  • 5,951
  • 1
  • 13
  • 24
0

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.

Erik Philips
  • 53,428
  • 11
  • 128
  • 150
MusiGenesis
  • 74,184
  • 40
  • 190
  • 334
  • I've tried this routine but to no avail as I was getting an error trying to find coredll.dll. It doesn't seem to exist on the machine. – Eric Jul 06 '12 at 21:06
  • Now what about getting the unique device ID through the web request? How can I achieve fetching it that way? – Eric Jul 06 '12 at 21:10
  • @Eric: coredll.dll should definitely be there on a windows mobile device. What you would do is write your web methods so that one of the parameters passed in is the client device's unique id, which the client would get using `GetDeviceUniqueID`. – MusiGenesis Jul 08 '12 at 23:23
0

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

Community
  • 1
  • 1
Erik Philips
  • 53,428
  • 11
  • 128
  • 150
  • When trying this it seems to get the MAC address from the server instead of the local machine. – Eric Jul 06 '12 at 21:28
  • I've tried http://stackoverflow.com/questions/4143323/how-to-get-mac-address-programatically-in-c-sharp-for-a-windows-mobile-6-0-devic – Eric Jul 06 '12 at 21:31
  • Ok I see, you have an incoming request and you want to assign that request a Unique ID. When I've programmed for CF Compact in 6.5, I call `GetDeviceUniqueID` which is executed on the client side and passed the value in the request to the server. – Erik Philips Jul 06 '12 at 21:32
  • Erik, I just tried GetDeviceUniqueID and error I'm getting is "Unable to load DLL 'coredll.dll': The specified module could not be found" Is it searching for it on the server or something? – Eric Jul 06 '12 at 21:44
  • Are you calling `GetDeviceUniqueID` on the *Windows Mobile Device*? – Erik Philips Jul 09 '12 at 16:38
0

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.

Eric
  • 7,930
  • 17
  • 96
  • 128