Reputation: 63
I need assistance in getting the users browser information, IP address and GEO location. We are developing asp.net application which we need the above information to track the user information from where he/she is accessing the application with browser/IP information. Below are the details we required and need to store in application database.
- Browser information/version
- Operating system
- Device (Desktop/laptop/Tablet/Mobile)
- IP address
- Country code/country name
- City
- Region
Is it possible to get all the information from once source? I have googled these and advised to use third party APIs to get geo information based on the IP address whether APIs are reliable to use the applications. Is there any best way to built own API to get this information and how? Please advice.
Upvotes: 3
Views: 6746
Reputation: 118
Just incase anybody else may need a shorter way to achieve the task mentioned in the question, they can use the code below;
<div id="demo"></div>
<script type="text/javascript">
var txt = "";
txt += "<p> Browser CodeName: <strong>"+navigator.appCodeName+" </strong></p>";
txt += "<p> Browser Name: <strong>"+navigator.appName+"</strong></p>";
txt += "<p> Browser Version: <strong>"+navigator.appVersion+"</strong></p>";
txt += "<p> Cookies Enabled: <strong>"+navigator.cookieEnabled+"</strong></p>";
txt += "<p> Browser Online: <strong>"+navigator.onLine+"</strong></p>";
txt += "<p> Language: <strong>"+navigator.language+"</strong></p>";
txt += "<p> Platform: <strong>"+navigator.platform+"</strong></p>";
txt += "<p> User-agent Header: <strong>"+navigator.userAgent+"</strong></p>";
document.getElementById("demo").innerHTML=txt;
</script>
Upvotes: 1
Reputation: 546
Try below javascript function, This will return Browser Name and Browser Version.
function get_browser()
{
var ua = navigator.userAgent, tem,
M=ua.match(/(opera|chrome|safari|firefox|msie|trident(?=\/))\/?\s*(\d+)/i) ||[];
if (/trident/i.test(M[1]))
{
tem = /\brv[ :]+(\d+)/g.exec(ua) || [];
return { name: 'IE', version: (tem[1] || '') };
}
if (M[1] === 'Chrome')
{
tem = ua.match(/\bOPR\/(\d+)/)
if (tem != null)
{
return { name: 'Opera', version: tem[1] };
}
}
M = M[2] ? [M[1], M[2]] : [navigator.appName, navigator.appVersion, '-?'];
if ((tem = ua.match(/version\/(\d+)/i)) != null)
{
M.splice(1, 1, tem[1]);
}
return {
name: M[0],
version: M[1]
};
}
Upvotes: 1