Click here to Skip to main content
11,571,102 members (68,885 online)
Rate this: bad
good
Please Sign up or sign in to vote.
Hello Everyone,

Can anyone help me ,

how to get client Ip Address and Machine using javascript or Jquery or any another .I have Googled so much ,But i didn't get correct results.

I have written server side code but it is giving my server details( Request.UserHostAddress & Dns.hostEntry ).

help me Please .
Posted 6-May-13 20:37pm
Comments
hemantrautela at 7-May-13 3:03am
   
Request.UserHostAddress property returns the remote User IP address, I also used it & it working fine....
Check your code once again.....
http://msdn.microsoft.com/en-us/library/system.web.httprequest.userhostaddress.aspx
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

 
<script type="text/javascript">
    window.onload = function () {
        var script = document.createElement("script");
        script.type = "text/javascript";
        script.src = "http://jsonip.appspot.com/?callback=DisplayIP";
        document.getElementsByTagName("head")[0].appendChild(script);
    };
    function DisplayIP(response) {
        document.getElementById("ipaddress").innerHTML = "Your IP Address is " + response.ip;
    }
</script>
</script>
  Permalink  
Comments
Hari Chandra Prasad Ravuri at 7-May-13 2:59am
   
Thank you perumal i had tried this also but i didn't Provide me required output
KM Perumal at 7-May-13 3:00am
   
what u ve did
Hari Chandra Prasad Ravuri at 7-May-13 3:09am
   
<script type="text/javascript">
var IpAddress="";
window.onload = function () {
var script = document.createElement("script");
script.type = "text/javascript";
script.src = "http://jsonip.appspot.com/?callback=DisplayIP";
document.getElementsByTagName("head")[0].appendChild(script);
};
function DisplayIP(response) {
IpAddress=response.ip;
}
</script>

i have used this script but i didn't get required output
KM Perumal at 7-May-13 3:17am
   
Hari this method ipaddress is label id if ur create Label as ipaddress u ll get ip address
function DisplayIP(response) {
document.getElementById("ipaddress").innerHTML = "Your IP Address is " + response.ip;
}
SHARIQ_KHAN at 19-Dec-14 8:18am
   
can we get the client machine name using this..?
Member 10230348 at 18-Jun-15 3:01am
   
how to store ip address in database using jquery can u explain me im new to jquery
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Hello,

There is no direct support for obtaining the ip address of the machine from JavaScript. But little bit server side code and AJAX you should be able to obtain the Ip address. So write a WebMethod which will retrieve the IP Address from the Request object and return it to caller. For AJAX you can use the very excellent JQuery library.

Regards,
  Permalink  
Comments
Hari Chandra Prasad Ravuri at 7-May-13 3:01am
   
Dear prasad,
Thanks for your solution i will try ur solution
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

Try This.

Hope it will helpful for you.
string ip = Request.UserHostAddress;
string hostname = Request.UserHostName;
  Permalink  
Comments
Hari Chandra Prasad Ravuri at 7-May-13 5:55am
   
Hi prashant
This code is giving my server Ip address and Machine Name

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS


Advertise | Privacy | Mobile
Web04 | 2.8.150624.2 | Last Updated 7 May 2013
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100