Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get client IP in vb.net

Tags:

vb.net

I am trying to get client ID with vb.net. My code is as under :

Partial Class foo
  Inherits System.Web.UI.Page
  Private ipv4 As New clsIPv4
  Dim ref As String = 0   

  Dim client_ip As String
  client_ip = Request.UserHostAddress()
  Dim myHost As String = System.Net.Dns.GetHostName()
  client_ip = ipv4.ResolveAddress(myHost)

This code is returning me list of ip adresses (i.e 182.50.130.143;118.139.172.1;118.139.172.2;118.139.172.3;118.139.172.4;118.139.172.5;118.139.172.6;118.139.172.7;118.139.172.8;118.139.172.9;118.139.172.10;118.139.172.11;118.139.172.12;118.139.172.13;118.139.172.14;118.139.172.15;118.139.172.16;118.139.172.17;118.139.172.18;118.139.172.19;118.139.172.20;118.139.172.21;118.139.172.22;118.139.172.23;118.139.172.24;118.139.172.25;118.139.172.26;118).

Please guide where I am wrong

like image 251
Amritpal singh Avatar asked May 18 '26 20:05

Amritpal singh


2 Answers

If you are using ASP.NET, you can use: Request.UserHostAddress to get your client IP address.

But if you are using a windows application to get local IP address, in fact you may receive multiple IP addresses! In this case, if you want to get a specific address which you know the netid part of the IP address you can compare all IP addresses with a corresponding netid address.

like image 52
gwt Avatar answered May 21 '26 13:05

gwt


This worked perfectly for me

System.Net.Dns.GetHostAddresses(System.Net.Dns.GetHostName()).GetValue(0).ToString()

like image 29
user2953513 Avatar answered May 21 '26 13:05

user2953513