Re: Searching for MySQL servers on the network by Blue
Blue
Thu Jun 30 17:53:04 CDT 2005
Ok, this is my solution and it seems to work:
'--- Start Script ---
For i = 90 to 120
strIP = "194.152.100." & CStr(i)
Set PingResults =
GetObject("winmgmts:{impersonationLevel=impersonate}//./root/cimv2").ExecQuery("SELECT
* FROM Win32_PingStatus WHERE Address = '" + strIP + "'")
For Each PingResult In PingResults
If PingResult.StatusCode = 0 Then
If LCase(strIP) = PingResult.ProtocolAddress Then
TestComputer(strIP)
End If
Next
Next
Sub TestComputer(strComputer)
Set MySQLProc = GetObject("winmgmts:\\" & strComputer &
"\root\cimv2").ExecQuery("Select * from Win32_Process",,48)
For Each ProcItem in MySQLProc
iProc = InStr(1, ProcItem.Caption, "mysqld", vbtextcompare)
If iProc > 0 Then Wscript.Echo strIP & " - " & GetComputerName(strIP)
Next
End Sub
Function GetComputerName(strCompName)
Set ComputerNames =
GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strCompName &
"\root\cimv2").ExecQuery("SELECT * FROM Win32_ComputerSystem")
For Each CNItem In ComputerNames
GetComputerName = CNItem.Name
Next
End Function
'--- End Script ---
Thank you all for who helped me out and tried to think with.
Arjan.
"Blue Ice" <noemailaddresstospam@the.newsgroup> wrote in message
news:e7HuwUbfFHA.3252@TK2MSFTNGP10.phx.gbl...
>I think you can get what you want by using WMI -> Win32_Process. It might
>be the solution to what you are looking for.
>
> Arjan
>
> "dmsys" <dmsys.nospmcaleb1@ntlworld.com> wrote in message
> news:42BFEEFE.32176CF4@ntlworld.com...
>> Please remove the quotes from findstr "processX.exe" (etc.)
>>
>> dmsys wrote:
>>
>>> No, not a lot of overhead, at least ours is very fast. You could use a
>>> simple
>>> batch file (.bat) like this, although it could be a lot more elaborate
>>> with wsh:
>>>
>>> tasklist /s server01 > server01.txt
>>> tasklist /s server02 > server02.txt
>>> tasklist /s server03 > server03.txt
>>> rem replace "processX.exe" with your target server's process
>>> findstr "processX.exe", server*.txt > svrproc.txt
>>> del server*.txt
>>> notepad svrproc.txt
>>>
>>> or you could further refine this elementary method to be more relevant
>>> to your
>>> needs:
>>>
>>> tasklist /s server01 > servers.txt
>>> tasklist /s server02 >> servers.txt
>>> tasklist /s server03 >> servers.txt
>>> rem replace "processSQ1.exe" with your target server's process
>>> echo ******************** SQ1 processes > svrproc.txt
>>> findstr processSQ1.exe, servers.txt > svrproc.txt
>>> echo ******************** SQ2 processes >> svrproc.txt
>>> rename servers.txt servers2.txt
>>> findstr "processSQ2.exe", servers2.txt >> svrproc.txt
>>> echo ******************** SQ3 processes >> svrproc.txt
>>> rename servers2.txt servers3.txt
>>> findstr "processSQ3.exe", servers3.txt >> svrproc.txt
>>> echo "" >> svrproc.txt
>>> del serv*.txt
>>> notepad svrproc.txt
>>>
>>> Note that if you use IPaddresses instead of hostnames, the script could
>>> hang if
>>> the server is unavailable.
>>> If you need more than the default four columns returned by tasklist, you
>>> may
>>> have to use wmi. Alternatively, if you find methods to return more than
>>> 4
>>> columns, or to return specific columns, please post.
>>>
>>> Regards.
>>>
>>> Blue Ice wrote:
>>>
>>> > That might be a good idea, although I am not sure that it runs just
>>> > one
>>> > single process. I believe that there 4 executables that can be used to
>>> > start
>>> > MySQL and it can be started as a service. However I will investigate
>>> > this
>>> > idea. By the way, would this create a lot overhead?
>>> > Thank you for the idea!
>>> >
>>> > Arjan.
>>> >
>>> > "dmsys" <dmsys.caleb1@ntlworld.com> wrote in message
>>> > news:42BD14E9.A74297A9@ntlworld.com...
>>> > > What process does mysql server execute on the computer? For
>>> > > instance, a
>>> > > computer running Microsoft Exchange Server _and_ is a mailbox server
>>> > > (not
>>> > > a
>>> > > front-end) will certainly have "store.exe" running. You can then run
>>> > > a
>>> > > command
>>> > > "tasklist" which dumps all the running processes. If instr
>>> > > store.exe, the
>>> > > computer is a mailbox server. A similar analogy should help with
>>> > > mysql.
>>> > >
>>> > > Blue Ice wrote:
>>> > >
>>> > >> Actually, I think that I have to send a signal to the computers in
>>> > >> the
>>> > >> network and wait until a computer answers. So when the computer is
>>> > >> a
>>> > >> MySQL
>>> > >> server, it will tell me that it is a MySQL server.
>>> > >>
>>> > >> Arjan.
>>> > >
>>
>
>