Link to home
Start Free TrialLog in
Avatar of _Katka_
_Katka_Flag for Czechia

asked on

How to detect running MySQL servers accross the LAN ?

Hi, experts!

Is there any way to detect running MySQL servers in single computer accessible via LAN ?

Condition:

The solution must return a listing of computers with MySQL server running (names prefered)

best regards,
Kate
Avatar of smurff
smurff

1: Find the port mysql runs on
2: Do a scan accross the network and try a simple connection to this port
3: Use the mysql client api to connect with a bogus user name and password
4: If you get the correct error response from mysql then you add the machines IP address to your list

regards
Smurff
By default MySQL is running on port 3306, but ... there is something to be considered: scanning across the LAN and trying telnet on port 3306 does not guarantee you have MySQL there. There may be some other program using this port.

I would suggest to try telnet to all hosts on your lan for e.g. 192.168.0.1 to 192.168.0.254. Then let's say 5 of these machines will have successful telnet on port 3306. It means that there is something there... After that you can try to connect to these machines using some DAC component for MySQL with user root and some random password. If it replies with MySQL message for wrong password - add it to the list.
Avatar of _Katka_

ASKER

Well, thanks for quick reply, but:

1) I don't know how to..
2) I don't know how to.
3,4) OK, I should be able to handle this

best regards,
Kate
ASKER CERTIFIED SOLUTION
Avatar of Russell Libby
Russell Libby
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of _Katka_

ASKER

Well, I've no comments, it works flawlessly and moreover it's finally a piece of code.

points and regards to Russel,
Kate
Nice piece of code mate. Are you sure it just finds MySql servers and not MSSql servers as well? I have found some other constants as well

SV_TYPE_WORKSTATION = $00000001;
SV_TYPE_SERVER = $00000002;
SV_TYPE_SQLSERVER = $00000004;
SV_TYPE_DOMAIN_CTRL = $00000008;
SV_TYPE_DOMAIN_BAKCTRL = $00000010;
SV_TYPE_TIME_SOURCE = $00000020;
SV_TYPE_AFP = $00000040;
SV_TYPE_NOVELL = $00000080;
SV_TYPE_DOMAIN_MEMBER = $00000100;
SV_TYPE_PRINTQ_SERVER = $00000200;
SV_TYPE_DIALIN_SERVER = $00000400;
SV_TYPE_XENIX_SERVER = $00000800;
SV_TYPE_SERVER_UNIX = SV_TYPE_XENIX_SERVER;
SV_TYPE_NT = $00001000;
SV_TYPE_WFW = $00002000;
SV_TYPE_SERVER_MFPN = $00004000;
SV_TYPE_SERVER_NT = $00008000;
SV_TYPE_POTENTIAL_BROWSER = $00010000;
SV_TYPE_BACKUP_BROWSER = $00020000;
SV_TYPE_MASTER_BROWSER = $00040000;
SV_TYPE_DOMAIN_MASTER = $00080000;
SV_TYPE_SERVER_OSF = $00100000;
SV_TYPE_SERVER_VMS = $00200000;
SV_TYPE_WINDOWS = $00400000; // Windows95 and above
SV_TYPE_DFS = $00800000; // Root of a DFS tree
SV_TYPE_CLUSTER_NT = $01000000; // NT Cluster
SV_TYPE_DCE = $10000000; // IBM DSS (Directory and Security Services) or
equivalent
SV_TYPE_ALTERNATE_XPORT = $20000000; // return list for alternate
transport
SV_TYPE_LOCAL_LIST_ONLY = $40000000; // Return local list only
SV_TYPE_DOMAIN_ENUM = $80000000;
SV_TYPE_ALL = $FFFFFFFF; // handy for NetServerEnum2
Avatar of _Katka_

ASKER

You're right smurff it only detects MS-SQL servers (which is also useful ;)

I used this piece of code with SV_TYPE_WORKSTATION parameter to detect all workstations in LAN and then
by checking port 3306 (what the heck about the alternative port settings) I determined if any service is running there.
Then I tried to connect to this host with my default user/password and in a case of failure I deleted it from list.

(because MySQL will be shiped with this product and also installed and configured by it)

best regards,
Kate

Beware the OVERLORD ultimate realtime workflow monitoring tool !
My bad on that ... "MySql"<->"MsSql"
And yes, there are a slew of const settings for the servertype param. Sorry for the confusion on that

Regards,
Russell

 

Russell dont be its still a nice piece of code :)

Kate, I think that the port thing is the only way to go otherwise your going to be doing a port scan on the whole PC and some detect that and just reject the packets.

Have a good xmas every1