Poppa Mintin
Well-known member
- Joined
- Jan 4, 2018
- Messages
- 45
- Programming Experience
- 10+
Hi,
I'm trying to find my WAN IP address. I think my code finds four results, the last of which I know in my LAN address.
The first three are reputed to be addresses in Hex. format but when I (think I) convert these to decimal, they don't resemble any IP address.
Where am I going wrong ?
(Try it out: zip attached)
Windows i7 machine. VS2017 latest update. (15.5.4.)
Poppa.
Oh! Do I have to apply a mask ?
Ok, I thought I might need to mask the result so I've tried:
And instead if the 'And' I've tried 'Or' and 'Xor', I can't find how to use Nand or Nor. I also tried 256.
None of those have actually worked, but the results look more likely, in most cases there were no minus numbers for example.
Pop.
I tried to delete my next post... couldn't find how to do that. Pop.
I'm trying to find my WAN IP address. I think my code finds four results, the last of which I know in my LAN address.
The first three are reputed to be addresses in Hex. format but when I (think I) convert these to decimal, they don't resemble any IP address.
VB.NET:
Imports System.IO
Imports System.Net
Imports System.Net.Sockets
Public Class Form1
Private Sub Form1_Load() Handles MyBase.Load
Button1.Text = "Exit"
Label1.Text = ""
WhoAmI()
End Sub
Private Sub Button1_Click() Handles Button1.Click
Me.Close()
End Sub
Private Sub WhoAmI()
Dim ad1, ad2, hostName As String
Dim i As Int32 ' (I use i after the loop is closed.)
Dim ipAddr() As IPAddress
hostName = System.Net.Dns.GetHostName()
ipAddr = Dns.GetHostAddresses(hostName)
For i = 0 To ipAddr.Count - 2
Label1.Text += vbCrLf & ipAddr(i).ToString & vbCrLf
ad1 = ipAddr(i).ToString
Dim splt() As String = Split(ad1, ":")
For j = 0 To splt.Count - 1
ad2 = splt(j)
' This next line is to remove any %(+) from Ad2.
' But it makes no difference to the result.
If Len(ad2) > 3 Then ad2 = ad2.Substring(0, 4)
ad2 = Val("&H" & ad2).ToString
Label1.Text += ad2 & " : "
Next
Label1.Text += vbCrLf
Next
Label1.Text += vbCrLf & "My LAN address is: " & ipAddr(i).ToString
End Sub
End Class
Where am I going wrong ?
(Try it out: zip attached)
Windows i7 machine. VS2017 latest update. (15.5.4.)
Poppa.
Oh! Do I have to apply a mask ?
Ok, I thought I might need to mask the result so I've tried:
VB.NET:
ad2 = Val(CInt(CInt(Val("&H" & ad2)) And 255)).ToString
And instead if the 'And' I've tried 'Or' and 'Xor', I can't find how to use Nand or Nor. I also tried 256.
None of those have actually worked, but the results look more likely, in most cases there were no minus numbers for example.
Pop.
I tried to delete my next post... couldn't find how to do that. Pop.
Last edited by a moderator: