What are your suggestions for discovering a MariaDB server on a local network? I know that port 3306 will be open, but I’m not sure about the best way to find out the server’s local IP address. (Yes, I wish the server was assigned a static IP address, but it’s not.)
I’ve been reading that the ICMP portocol doesn’t actually check to see if a particular port is open, but they state that one should use either the UDP or TCP protocols. Am I on the right track? Just scan each of the 255 IP address on the local network to see which one connects successfully?
Theirs is a very “basic” model that just assigns dynamic IP addresses (and not static ones), unfortunately. This is why I am trying to figure out how to scan for which IP has the open port.
@Kem Tekinay The areas of control that I have are the Xojo software that I’m writing and also the database (Mariadb) configuration. Outside of that, it’s in their hands, and not so much mine, which is why I’m trying to port scan to find the server.
I just figured out how to create a solution in Python 3, in case anyone else needs a script to quickly search for a server on a local network. In Xojo, you can use the Shell to get the results from the Python script.
[code]import socket
ports = []
for x in range(1, 256):
ports.append(“192.168.1.” + str(x))
for p in ports:
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
try:
s.settimeout(0.25)
s.connect((p, 3306))
print(p)
except:
continue[/code]
Sorry Byron, I read this earlier and thought you were ok doing it in Xojo and were just asking for ways of how to find the service, here you go, its quick and dirty, plenty of room to bling it up:
Wow, that is AMAZING!! Thank you so much… Yes, I didn’t know exactly how to go about it, so I was trying to figure out how to accomplish it – one way, or another!
But don’t assume the base IP as “192.168.0” and later the last part. Grab it from the network like:
[code]Private Function GetBaseIP() as String
Dim thisLocalAddrParts() As String = TCPSocket(New TCPSocket).LocalAddress.Split(".") // your IP
thisLocalAddrParts.Remove(3) // Remove the last part
Return Join(thisLocalAddrParts, “.”) // Return “192.168.33” or other and just add “.nnn” other numbers
[quote=471013:@Rick Araujo]Private Function GetBaseIP() as String
Dim thisLocalAddrParts() As String = TCPSocket(New TCPSocket).LocalAddress.Split(".") // your IP
thisLocalAddrParts.Remove(3) // Remove the last part
Return Join(thisLocalAddrParts, “.”) // Return “192.168.33” or other and just add “.nnn” other numbers
End Function[/quote]
This function supposes there is only ONE networkadapter on the computer. If you have installed vmware or virtualbox or a bluetooth-adapter there are more base IP’s on the system and then it’s unlikely this function returns the wanted base IP.
Nope, this function does not makes assumptions, just returns the first 3/4 of the current IP your app is bind to, what “I” supposed, based on the codes exposed, was that the app was intended to run in a simple local network, and people assuming fixed prefixes, causing more pain than gain when such app was moving around in other environments. And If you know in advance so much data about the network to hardcode it, you don’t need to scan it, just set the IP and port in a config.
One way of finding a machine in a LAN of whatever class, is making an UDP beacon service, and installing it in the same machine of the server. Then your app send a broadcast message to 255.255.255.255 and wait for a report from the beacon telling you where the server is.