VikasReddy Jali

VikasReddy Jali

  • NA
  • 44
  • 622

Get IPAddresses of all the systems connected to a website

May 23 2017 12:58 AM
protected void Page_Load(object sender, EventArgs e) 
    {        
   string myExternalIP;   
   string strHostName = System.Net.Dns.GetHostName(); 
      string clientIPAddress = System.Net.Dns.GetHostAddresses(strHostName).GetValue(0).ToString();   
   string clientip = clientIPAddress.ToString();  
   System.Net.HttpWebRequest request = (System.Net.HttpWebRequest)System.Net.HttpWebRequest.Create("https://www.google.co.in/webhp?hl=en&sa=X&ved=0ahUKEwj1lsmrxdPTAhXFL48KHWLaD90QPAgD/xml/");         
    request.UserAgent = "User-Agent: InternetExplorer/4.0(compatible;MSIE" + "6.0;Windows NT 5.1;sv1;.NET CLR 1.1.4322;.NET CLR 2.0.50727)";  
    request.Method = "GET";      
       //request.Credentials = CredentialCache.DefaultCredentials;    
         HttpWebResponse response = (HttpWebResponse)request.GetResponse();    
         StreamReader reader = new StreamReader(response.GetResponseStream());   
          { 
                myExternalIP = reader.ReadToEnd();    
             reader.Close();   
          }    
         TextBox1.Text = myExternalIP.ToString();    
       }      
   private DataTable GetLocation(string ipaddress)     
    {  
           WebRequest rssReq = WebRequest.Create("https://www.google.co.in/webhp?hl=en&sa=X&ved=0ahUKEwj1lsmrxdPTAhXFL48KHWLaD90QPAgD/xml/" + ipaddress);         
    WebProxy px = new WebProxy("https://www.google.co.in/webhp?hl=en&sa=X&ved=0ahUKEwj1lsmrxdPTAhXFL48KHWLaD90QPAgD/xml/" + ipaddress, true);      
       rssReq.Proxy = px; 
            rssReq.Timeout = 2000;    
         try    
         { 
                WebResponse rep = rssReq.GetResponse();     
            XmlTextReader xtr = new XmlTextReader(rep.GetResponseStream());   
              DataSet ds = new DataSet();     
            ds.ReadXml(xtr);       
          return ds.Tables[0];     
        }  
           catch   
          {     
            return null;    
         }  
      }

Answers (2)