Click here to Skip to main content
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 21: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 10 hrs ago
   
can we get the client machine name using this..?
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
0 OriginalGriff 245
1 Kamal Rocks 184
2 Sergey Alexandrovich Kryukov 175
3 BillWoodruff 173
4 PIEBALDconsult 160
0 OriginalGriff 5,655
1 DamithSL 4,506
2 Maciej Los 3,997
3 Kornfeld Eliyahu Peter 3,480
4 Sergey Alexandrovich Kryukov 3,180


Advertise | Privacy | Mobile
Web02 | 2.8.141216.1 | Last Updated 7 May 2013
Copyright © CodeProject, 1999-2014
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