I have this code:
localIp = Request.UserHostName
hostName = DetermineCompName(localIp)
Session.Add("localIp", localIp)
Session.Add("hostName", hostName)
As you can see, I put the 2 variables on a session so that I can use it when I want. Testing the app on 10 computers, I saw that on some of the computers it gets the Client IP and the Computer name, but on others it goes empty.
As in some computers it works, I don't understand what's wrong. Does anyone have the right method to do this?
To get the computer name you can simply do:
Dim hostName As String = Environment.MachineName
or:
Dim hostName As String = My.Computer.Name
For the IP it's a little bit trickier, I assume you want the ipV4, so you can try this:
Dim localIp As String
For Each address As System.Net.IPAddress In System.Net.Dns.GetHostEntry(System.Net.Dns.GetHostName).AddressList
If address.AddressFamily = Net.Sockets.AddressFamily.InterNetwork Then
localIp = address.ToString()
Exit For
End If
Next
Please note that if you do just:
System.Net.Dns.GetHostEntry(System.Net.Dns.GetHostName).AddressList(0).ToString()
then this will return the ipV6.
Related
My question is How To Get Domain Name From Ip address Any ideas Will Be Accepted
I'm searching for that For 3 days no answer at all.
I want the program to work with unknown websites "I Create It Or The User Which he used It"
I give the IP address and the program will give me all the domain names For that server Like 216.58.211.100 >>>>> the result will bw >>>>>>www.google.com.
That it's so important to me right now. Why is it so difficult to do it? Any idea? I prefer VB.Net, but it's Ok with other languages or ideas. Thanks in advance.
nslookup (wiki)
or this script should help https://gist.github.com/jrothmanshore/2656003
I got this. It's good for me.
Dim validip As Boolean
ListBox1.Items.Clear()
Dim ipHost As IPHostEntry = New IPHostEntry()
Application.DoEvents()
Try
ipHost = Dns.GetHostEntry(TextBox10.Text)
validip = True
Catch se As SocketException
Dim message = se.Message.ToLower()
If message.Equals("no such host is known") Then
validip = False
Else
Throw
End If
End Try
If validip Then
For Each ip As IPAddress In ipHost.AddressList
ListBox1.Items.Add(ip.AddressFamily.ToString())
ListBox1.Items.Add(ip.ToString())
Next
ListBox1.Items.Add("Host name is : " & ipHost.HostName)
Else
ListBox1.Items.Add("Could not resolve unknown host.")
End If
I am stuck while getting ip4 address from my computer with 2 network card and 1 wifi card.
The code i am using to get IP address is this :
'Get Network Information
hostName = System.Net.Dns.GetHostName()
Dim hostEntry = Dns.GetHostEntry(hostName)
Dim addressList As New List(Of IPAddress)
For Each address In hostEntry.AddressList
If address.AddressFamily = Sockets.AddressFamily.InterNetwork Then
addressList.Add(address)
End If
Next
The problem is, if i used this code to get the ip address into a text box, it didn't always show the ip address my computer is currently active :
teIP4.Text = addressList(0).ToString
Edit : I am trying to connect to SQL Server via LAN but still in a and inserting my ip address to the database for further use, so i need to get the active ip address.
Is there anyway to specify which IP Address is currently active from code? Thanks!
What I'm looking to acquire is ip addresses from a webpage which contains the information.
Example page: http://www.game-monitor.com
I'm basically looking how to make vb.net visit that webpage and save the IP Addresses it gets from that webpage.
Thanks!
Check the System.Net.NetworkInformation for the Ping method. You can ping the hostname and return the IP to a variable.
Dim ping as Ping = New Ping()
Dim pingReply as PingReply = ping.send("www.game-monitor.com")
Dim ip as String = PingReply.Address.ToString()
Edit, you might want to add a try catch in case the ping doesn't get a reply.
Currently I use the following code to retrieve the IP address of the local workstation...
strIPAddress = System.Net.Dns.GetHostEntry(strComputerName).AddressList(0).ToString()
This is fine for the Windows XP workstations. However, in Vista and Windows 7, this returns the IPv6 address which is not used at all. Is there a method of setting this to work so it always returns the IPv4 address regardless of platform?
I know I can increment the AddressList value to 1 and get the correct IP in Windows 7. The bad part is that this requires going through the motions of identifying the OS and choosing one or the other.
The must be some way of specifying IPv4 only. Perhaps getting a result from DNS on the network rather than the workstation itself?
You just need to loop through the AddressList looking at the AddressFamily seeing which is set to InterNetwork
Dim IP4 = New List(Of IPAddress)(Dns.GetHostEntry(strComputer).AddressList).Find(Function(f) f.AddressFamily = Sockets.AddressFamily.InterNetwork)
Or the longer way:
Dim IP4 As IPAddress
Dim AL = Dns.GetHostEntry(strComputer).AddressList
For Each A In AL
If A.AddressFamily = Sockets.AddressFamily.InterNetwork Then
IP4 = A
Exit For
End If
Next
I have a Windows forms application running on a terminal server. I need to determine the IP addresses of each client machine.
I found a way to retreive the IP address for computers with DNS entries (example below), but several of my thin clients were set up with static IPs and have no DNS name. Is there a way to determine the IP address of a remote client without having a DNS name?
Dim clientName As String = My.Computer.Network.ClientName
Dim IPHost As Net.IPHostEntry = Net.Dns.Resolve(clientName & "domain.com")
Dim addresses As Net.IPAddress() = IPHost.AddressList
fullIP = addresses(0).ToString()
To get the primary IP Address, you can use:
System.Net.Dns.GetHostEntry("").AddressList(0).ToString
This may return an IP6 address, in which case you can try to find the IP4 using:
Dim ipentry As System.Net.IPHostEntry = System.Net.Dns.GetHostEntry("")
For i As Integer = 0 To ipentry.AddressList.Count - 1
MsgBox(System.Net.Dns.GetHostEntry("").AddressList(i).ToString)
Next