How To Get Domain Name From IP? - vb.net

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

Related

Get the IP and Computer Name

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.

SQLite database file can't be opened when placed in network folder

Can someone help me to understand why this works fine...
Dim cs = "Data Source=C:\folder\Livros.sdb;Version=3;"
Dim cn = New System.Data.SQLite.SQLiteConnection(cs)
cn.Open() ' no exception
... while this breaks when opening connection (it is exactly the same file)...
Dim cs = "Data Source=\\NetworkServer\folder\Livros.sdb;Version=3;"
Dim cn = New System.Data.SQLite.SQLiteConnection(cs)
cn.Open() ' exception: {"unable to open database file"}
... and fix it because I need to place database file in network location so I can access it regardless of the computer I run the application?
Thank you very much!
Ok, so by trial and error I found the solution, although I can't quite understand the reason it works:
Dim cs = "Data Source=\\NetworkServer\folder\Livros.sdb;Version=3;"
Dim cn = New System.Data.SQLite.SQLiteConnection(cs)
cn.ParseViaFramework = True ' JUST ADDED THIS STATEMENT
cn.Open() ' no exception
If somebody can explain why .ParseViaFramework = True does the trick, please feel free to comment.
Similar question was asked here.
SQLite: Cannot open network file programmatically, even though worked before
The top answer gives a few more fixes. Linking here as this is the first stackoverflow that came up when I searched. Also I was using a SQLiteConnectionStringBuilder and could not find a way to set the parseViaFramework so the first solution was the one I needed.
Double the leading two backslashes in the file name (e.g. "\\\\network\share\file.db").
Use a mapped drive letter.
Use the SQLiteConnection constructor that takes the parseViaFramework boolean argument and pass 'true' for that argument.

TCP/IP Messaging Application VB.net - IP Address / Port-Forwarding Questions

I am developing a piece of scientific software in VB.net that I intend to distribute. Part of the application will involve communication with a server (and other clients). For all intents and purposes the communication will be like a chat application.
I have developed the software using sockets, and it works fine when testing at home on my local network. Below is basically how I send messages:
Dim serverIPString as String = "192.168.1.5"
Dim serverPort as long = 65500
dim messageString as String = "Hello"
Dim Client As New System.Net.Sockets.TcpClient(serverIPString, serverPort)
Dim Writer As System.IO.StreamWriter(Client.GetStream())
Writer.Write(messageString)
Writer.Flush()
Writer.Close()
And this is how I listen:
Public Class TCPIPListener
Dim initalised As Boolean = False
Dim port As Long
Dim IP As System.Net.IPAddress
Dim ourListener As TcpListener
Dim ourClient As TcpClient
Dim ourMessage As String
'''''''''''
'' ctors ''
'''''''''''
Public Sub New()
initalised = False
End Sub
'Takes IP and port and starts listeing
Public Sub New(inIP As String, inPort As Long, inExchange As messageExchange)
'Try to set the IP
Try
IP = System.Net.IPAddress.Parse(inIP)
Catch ex As Exception
Exit Sub
End Try
'Set the port
port = inPort
initalised = startListener()
End Sub
'''''''''''''''
'' Listening ''
'''''''''''''''
Private Sub Listening()
ourListener.Start()
End Sub
'starts listener
Public Function startListener() As Boolean
ourListener = New TcpListener(IP, port)
ourClient = New TcpClient()
Dim ListenerThread As New Thread(New ThreadStart(AddressOf Listening))
ListenerThread.Start()
initalised = True
Return True
End Function
'Called from a timer on the form
Public Function tick() As Boolean
If Not initalised Then
Return False
End If
If ourListener.Pending = True Then
ourMessage = ""
ourClient = ourListener.AcceptTcpClient()
Dim Reader As New System.IO.StreamReader(ourClient.GetStream())
While Reader.Peek > -1
ourMessage = ourMessage + Convert.ToChar(Reader.Read()).ToString
End While
messagebox(ourMessage)
End If
Return True
End Function
End Class
Using this approach, every client will be listening for messages sent from the server, and any messages sent will go to the server and be directed to the relevant client - it's a little inefficient but necessary for the way my software works.
The problem is that I am having real trouble getting this to work across the internet. If I send a message to a local IP address it works fine, even from the debugger. If I use a external IP address I get the following:
No connection could be made because the target machine actively refused it XXX.XXX.XXX.XXX:65500"
I have turned on port forwarding with my router and set up the correct port (65500 here) to forward to my PC running the lister (192.168.1.5) for both TCP and UDP. This website it tells me this port is open, and those either side are not.
If I right click on the exe and run as administrator, my antivirus pops up and says it is doing something suspicious when I start the listener (which I guess if anything is encouraging). If I then add my application to the list of exceptions and run it again, then check to see if the port is listening (using this) I find my application listening on the correct port (if I stop the application it is gone). However the client application still gives the same error above. If I use a random IP address rather than the one of the listener I get a different error:
{"A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond XXX.XXX.XXX.XXX:65500"}
I suspect I am not taking the correct approach to this. I am fine with most aspects of VB, but have not really tackled this sort of problem before. When it comes to distributing software I really don't want my customers to have to mess around with deep settings to get this application to work. Any help will be immensely useful to me!
Another problem I guess I will face in the future is if multiple clients have the same external IP but different internal IPs (I intend to distribute to universities). Under these circumstances I guess port forwarding will not work.
Thanks very much in advance (and apologies for the long post)!
If you set your server to listen for connections on 192.168.1.5 then it will only allow connections from that specific IP address. The address you give a TcpListener is the IP address which you will accept connections from.
Since the 192.168.1.5 address is internal no one outside your network will be able to connect to your server. Make your server listen to 0.0.0.0 (or the equivalent IPAddress.Any) instead to make it allow connections from anyone.

Authenticating against ADAM using LDAP

I'm trying to authenticate using ADAM and LDAP. I really have no experience with this stuff, but I've been thrown in the deep end at work to figure it out.
Here's what I know. I'm using a program called JXplorer to look at the ADAM server, running on a VM on my computer. Here are the login details
This works perfectly. What I'm trying to do is replicate this process using VB.NET. I've tried a bunch of stuff and nothing seems to be working, I'm getting constant exceptions, ranging from bad password to unknown error. Here's the code I've started with -
Dim userName As String = "ADAM_TESTER"
Dim userPassword As String = "password"
Dim serverAddress As String = "LDAP://10.0.0.142:389"
Private Sub Main_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Try
Dim de As DirectoryEntry = New DirectoryEntry("LDAP://10.0.0.142:389/OU=Users,DC=TEST,DC=corp", userName, userPassword)
Dim deSearch As DirectorySearcher = New DirectorySearcher()
deSearch.SearchRoot = de
deSearch.Filter = "(&(objectClass=user) (cn=" + userName + "))"
Dim results As SearchResultCollection = deSearch.FindAll()
If (results.Count > 0) Then
Dim d As DirectoryEntry = New DirectoryEntry(results(0).Path, userName, userPassword)
If (d.Guid.ToString IsNot Nothing) Then
'The directory entry is valid
'DoSomething()
End If
End If
I've also tried changing the userName above to the details in User DN in JXplorer. I'm really stuck here and have been looking for answers for hours.
Any help would be appreciated.
FYI, Users is a container, not an OU. I believe you could have also used "LDAP://10.0.0.142:389/CN=Users,DC=TEST,DC=corp"
It is almost certainly a need for userName to be the full DN. ADAM needs a full DN for logins in most cases.
Thanks for the thoughts Geoff, I eventually figured it out. It turned out that I needed the connection string not including the OU=Users. The final string ended up being -
LDAP://10.0.0.142:389/DC=TEST,DC=corp
I've no idea why it didn't want the OU=Users. I spend about a day trying all the different combinations until finally this was accepted.

Get certain text from a webpage [VB.NET]

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.