Computer list (SARS-2)

229 views
Skip to first unread message

Appliserver

unread,
Apr 1, 2020, 5:44:58 AM4/1/20
to harbou...@googlegroups.com
I am writing a small program that should emit commands to other PCs in
the LAN (mainly shutdown and wake-on-lan and yes, that's related with
SARS-2 and smart working). I would like to obtain the list of networked
computers.

After some searches I found some Windows functions: WNetOpenEnum(),
WNetEnumResource(), WNetCloseEnum(). They need a wrapper to Harbour and
since my knowledge of C is minimal it would be a difficult task for me.

I found also the possibility to use WMI and that does not involve C
programming:
local oLoc:=createObject("wbemScripting.SwbemLocator")
local oSrv:=oLoc:ConnectServer()
local oCollection:=oSrv:ExecQuery("Select * from win32_ComputerSystem")
local oItm
for each oItm in oCollection
alert(oItm:Workgroup())
next oItm
That works, but I can only query the local computer, and the class
win32_ComputerSystem has no informations about other networked PCs. The
ConnectServer method accepts a computername and should then query a
remote computer too.
But where to find the list of the workgroup's computers? The local
computer should keep such a list somewhere... but I am at lost with the
many classes available and the query's syntax (if that approach is
viable, and I even don't know if it is)

Has anybody tried to do that? Any hints?
Dan

Francesco Perillo

unread,
Apr 1, 2020, 6:19:04 AM4/1/20
to harbou...@googlegroups.com
if there is already a command line program that provides this functionality, why don't you just call it and then parse the result?

In case of windows shares I think that there is a NETBIOS locator or something similar that keeps a list of all connected computers. You may query it.

The solution can be different depending on what you need to obtain or what your share server is... (for example I use a linux server and with smcstatus command I have a list of all the clients logged in (they may be turned on but not logged as far as I know)).

The catch-all solution is to set a wakeup time in the BIOS... almost all BIOS have this feature: swtich it on at 7:00 am and turn it off by some windows feature after X hours of not use, or at specific time. It all depends on what you need.

BTW: are you sure the Wake-on-lan feature is working on your motherbords?





--
--
You received this message because you are subscribed to the Google
Groups "Harbour Users" group.
Unsubscribe: harbour-user...@googlegroups.com
Web: http://groups.google.com/group/harbour-users

---
You received this message because you are subscribed to the Google Groups "Harbour Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to harbour-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/harbour-users/232acefa-9eff-436d-01ab-9cda2f494ecd%40appliserver.com.

Appliserver

unread,
Apr 1, 2020, 8:02:31 AM4/1/20
to harbou...@googlegroups.com

Thank you for your time!


On 04/01/2020 12:18 PM, Francesco Perillo wrote:
if there is already a command line program that provides this functionality, why don't you just call it and then parse the result?

OK but what command line program? I have no problems at all to call external programs and parse the output.


In case of windows shares I think that there is a NETBIOS locator or something similar that keeps a list of all connected computers. You may query it.

Eh, indeed that is the main question. What and how?


The solution can be different depending on what you need to obtain or what your share server is... (for example I use a linux server and with smcstatus command I have a list of all the clients logged in (they may be turned on but not logged as far as I know)).

Yep I too have a Linux Samba server in some (but not all) environments , and I am looking for a solution unaware of the underlying SMB software.

The catch-all solution is to set a wakeup time in the BIOS... almost all BIOS have this feature: swtich it on at 7:00 am and turn it off by some windows feature after X hours of not use, or at specific time. It all depends on what you need.

Yes of course, to be on the safer side, where it's available, the BIOS option "Wakeup on RTC" is set to "8:00, daily" and the scheduled shutdown is set at 2:00 PM.

Moreover, when available, PCs are set for wake up on LAN.
Moreover, I want to implement the possibility to shutdown/reboot a PC if needed at any time.


BTW: are you sure the Wake-on-lan feature is working on your motherbords?

The ones that are, have been tested and enlisted!

Francesco Perillo

unread,
Apr 1, 2020, 3:34:15 PM4/1/20
to harbou...@googlegroups.com
I remember to have used nbtstat on windows, and "arp -a"

smbstatus on samba server

can you please say what yo need exactly, not what you tried to achieve it.

Appliserver

unread,
Apr 1, 2020, 8:17:19 PM4/1/20
to harbou...@googlegroups.com
On 04/01/2020 09:33 PM, Francesco Perillo wrote:
> I remember to have used nbtstat on windows, and "arp -a"
>
Uhm I tried them (thank you), but the output is hardly useful. The first
(nbtstat -s or nbtstat -r) gives some computers but not all. The second
gives a list of IP addresses but I really don't understand where they
are from.
> smbstatus on samba server
>
smbstatus is for Linux clients.

> can you please say what yo need exactly, not what you tried to achieve it.
??? what's unclear from my OP:
"I would like to obtain the list of networked
computers."

Dan

Francesco Perillo

unread,
Apr 2, 2020, 3:48:15 AM4/2/20
to harbou...@googlegroups.com
Hi Dan,

??? what's unclear from my OP:
"I would like to obtain the list of networked
computers."

Sorry, to me "networked computers" is a too broad definition.

I can say that in the past we used two methods to gather informations on PC connected to a network via cable:
- PING to broadcast (it was possible at the time, should be still, but you need to check) so that every PC that is ON (also not logged) will reply. From the arp table or the reply you can list the connected PC
- PING to every address in the space. If your network is 192.168.X.Y/24 you may have only 256 pc connected, ping each one and if they reply you will know which one is ON. Of course if you have a /16 network or, worse, a /8 network it will be impossible
- on a /8, segmented network, we created a script that queried all the routers and dumped the IPs registered on each port, doing the query every X minutes.

You may also call smbstatus every 10 minutes and collect the IPs.

If you have a server other than samba, like an internal web server, an internal antivirus server, a NTP server, or better yet a DNS server, you may access their log and extract the IP. The DNS server is a fantastic way to intercept all the PC that are ON but do not login to samba: when Windows starts it performs a lot of DNS queries... 

Appliserver

unread,
Apr 2, 2020, 5:29:23 PM4/2/20
to harbou...@googlegroups.com
On 04/02/2020 09:47 AM, Francesco Perillo wrote:
Hi Dan,

??? what's unclear from my OP:
"I would like to obtain the list of networked
computers."

Sorry, to me "networked computers" is a too broad definition.

Eh, yes, it is :-) I mean computers in the LAN (no domain). Yesterday I tried another way: a query via ADO to ADsDSOObject, but there is no Active Directory in this network (Samba server) so it didn't work (but I will test on another LAN with Windows server 2012).


I can say that in the past we used two methods to gather informations on PC connected to a network via cable:
- PING to broadcast (it was possible at the time, should be still, but you need to check) so that every PC that is ON (also not logged) will reply. From the arp table or the reply you can list the connected PC
That's interesting. I tried nmap -ds (under Linux), it does the same, pinging all addresses of the subnet (.../24=255 addresses).


- PING to every address in the space. If your network is 192.168.X.Y/24 you may have only 256 pc connected, ping each one and if they reply you will know which one is ON. Of course if you have a /16 network or, worse, a /8 network it will be impossible
- on a /8, segmented network, we created a script that queried all the routers and dumped the IPs registered on each port, doing the query every X minutes.

Ugh

You may also call smbstatus every 10 minutes and collect the IPs.

If you have a server other than samba, like an internal web server, an internal antivirus server, a NTP server, or better yet a DNS server, you may access their log and extract the IP. The DNS server is a fantastic way to intercept all the PC that are ON but do not login to samba: when Windows starts it performs a lot of DNS queries... 

I would like to know how to query dnsmasq for that... I was not able to. But anyway that's from Linux, I need something working on Windows side.
Still nvestigating...
Dan

BM16

unread,
Apr 3, 2020, 6:06:16 AM4/3/20
to harbou...@googlegroups.com

Hello,

 

If you use Windows, maybe you can take some idea here :

http://www.goldenstag.net/dbase/

 

Download dUFLPPlus_12A.zip

 

In NetSender.wfm ( open like a txt file )

 

Look : function GetNetworkComputers() and function GetNetworkDomains()

 

It easy to translate

 

Regards,

 

Bernard

 

.

Bernard Mouille

unread,
Apr 4, 2020, 2:25:56 AM4/4/20
to Harbour Users
I have put a response with Microsoft Outlook software but it do not change the banner of the discussion.
Bernard 
Reply all
Reply to author
Forward
0 new messages