1

I'm making a WPF application. How can I get the person who is using my application country name and timestamp. I have no clue how this should be done, I'm guessing that we need the user's IP address?

Jon Skeet
  • 1,421,763
  • 867
  • 9,128
  • 9,194
Loc Dai Le
  • 1,661
  • 4
  • 35
  • 70
  • 1
    By asking them in the UI? – Phylogenesis Oct 01 '15 at 13:03
  • 3
    What do you mean by "country name" anyway? The place where they currently are physically, or their home country? What do you mean by "timestamp" in this case? If you're looking for their time zone, there's a lot more too it than country... I'm afraid you'll need to give a lot more information before we can really answer - and bear in mind that things like IP geolocation can be affected by proxies, VPNs etc. – Jon Skeet Oct 01 '15 at 13:07
  • You can use this guide to translate a user's IP address to country: http://www.codeproject.com/Articles/28363/How-to-convert-IP-address-to-country-name – Maor Veitsman Oct 01 '15 at 13:09
  • Yes the place where they currently are physically and the date and time for that place. I want these information send to my DB to see where people uses my application. – Loc Dai Le Oct 01 '15 at 13:09
  • 1
    Don't rely on geolocation - it will break when people are using proxies and/or something like tor. It's common courtesy to ask the user if you want to transmit usage statistics, so if you're asking anyway why not ask which country they are in at the same time (by all means use geolocation to give the default answer)? – Phylogenesis Oct 01 '15 at 13:12

1 Answers1

1
String CountryShortCode=GetCountry();

And Method goes like this

 static public string GetCountry()
    {
        return new WebClient().DownloadString("http://api.hostip.info/country.php");
    }

Then set TimeZone using CountryShortCode to get TimeStamp according to ThatCountry

This link is working : http://www.aspsnippets.com/Articles/How-to-get-Country-Name-from-IP-Address-in-ASPNet-using-C-and-VBNet.aspx

Rajan Kali
  • 12,627
  • 3
  • 25
  • 37