Discovering a Local Server's IP Address?

Hello,

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?

Suggestions?

you can not use the hostname?

at my internet router i have a option to assign allways the same ip. using the pc name is the better way.

local at same pc it would be ip 127.0.0.1

documentation.xojo.com/api/databases/database.html#database-host

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. :wink:

Do you have any control over the server? Can you configure it manually or install anything on it?

this is a method, but it’s awfully slow. the icmp one will give faster results.
or use bonjour if the mariadb advertise with it.

here an icmp example ( for realbasic) : https://charlie.boisseau.uk/

@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. :wink:

@Jean-Yves Pochez Thank you! I’ll look into this… Much appreciated! :slight_smile:

That setup is… unusual.

I have no experience with MariaDb (and little with MySQL), so let me spitball…

Can you write a MariaDB function on a timer that does can call, for example, command line tools to register the address to a known location?

there is a bonjour scan example in the macoslib project.
if you’re on a mac ?

Hey everyone,

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]

Yay! Whew… I hope this helps anyone who needs it!

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:

https://www.dropbox.com/s/5f397h5l6vxokub/TestPortScan.xojo_binary_project?dl=0

Its almost instant because the requests are threaded off so we don’t have to worry about timeouts. Hope it helps.

Hi Julian,

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! :wink:

Again, thank you! :slight_smile:

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

End Function[/code]

And the range must be 0…254. 255 is reserved for broadcasting.

Yeah, don’t assume that the db is on the same network as the app server either, I’d hope they know what to put in there.

Also don’t assume they on a class c network, 255 is valid for other classes.

[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.