Discovering a Local Server's IP Address?

  1. 3 months ago
    Edited 3 months ago

    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?

    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.

  2. Markus R

    Jan 10 Pre-Release Testers, Xojo Pro Europe / Germany / Lower Saxon...
    Edited 3 months ago

    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

    docs.xojo.com/Database.Host

    The database host name or IP address of the database server.

  3. Edited 3 months ago

    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. ;-)

  4. Kem T

    Jan 10 Pre-Release Testers, Xojo Pro, XDC Speakers, MVP Connecticut

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

  5. Jean-Yves P

    Jan 10 Pre-Release Testers, Xojo Pro Europe (France, Besançon)
    Edited 3 months ago

    @Byron M Just scan each of the 255 IP address on the local network to see which one connects successfully?

    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/

  6. @Kem T 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. ;-)

  7. @Jean-YvesPochez Thank you! I'll look into this... Much appreciated! :-)

  8. Kem T

    Jan 10 Pre-Release Testers, Xojo Pro, XDC Speakers, MVP Connecticut

    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?

  9. Jean-Yves P

    Jan 10 Pre-Release Testers, Xojo Pro Europe (France, Besançon)

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

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

    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

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

  11. Julian S

    Jan 10 Pre-Release Testers, Xojo Pro Answer UK

    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.

  12. Edited 3 months ago

    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! ;-)

    Again, thank you! :-)

  13. Rick A

    Jan 10 Pre-Release Testers (Brazil. UTC-3:00)
    Edited 3 months ago

    But don't assume the base IP as "192.168.0" and later the last part. Grab it from the network like:

    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
  14. Rick A

    Jan 10 Pre-Release Testers (Brazil. UTC-3:00)

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

  15. Julian S

    Jan 10 Pre-Release Testers, Xojo Pro UK

    @Rick A But don't assume the base IP as "192.168.0" and later the last part.

    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.

    @Rick A And the range must be 0..254. 255 is reserved for broadcasting.

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

  16. Andre K

    Jan 11 Pre-Release Testers

    @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

    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.

  17. Rick A

    Jan 11 Pre-Release Testers (Brazil. UTC-3:00)
    Edited 3 months ago

    @Andre K This function supposes there is only ONE networkadapter on the computer

    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.

  18. Rick A

    Jan 11 Pre-Release Testers (Brazil. UTC-3:00)
    Edited 3 months ago

    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.

or Sign Up to reply!