thx, Martin
How to get Network IP over LAN
How to get Network IP over LAN
I try to find out the IPs of all computers that are connected to my PC over LAN. Anybody got an idea how to manage this ?
thx, Martin
thx, Martin
an example of what you are expecting exists in CodeArchive. This is in german ( so, take your dictionnary close to you
) and make use of the MS API structure BROWSEINFOS. here is the entire code :
Code: Select all
; German forum: http://robsite.de/php/pureboard/viewtopic.php?t=669&highlight=
; Author: Manne
; Date: 19. April 2003
; Beispiel wie man Clients im LAN remote herunterfahren oder neustarten kann.
; Optional kann auch eine Nachricht gesendet werden.
; Logischerweise muß der Initiator auf dem Client Adminrechte haben
#ERROR_SUCCESS = 0
#MAX_PATH = 260
#CSIDL_NETWORK = $12
#BIF_BROWSEFORCOMPUTER = $1000
Structure BROWSEINFOS
hwndOwner.l
pidlRoot.l
pszDisplayName.s
lpszTitle.s
ulFlags.l
lpfn.l
lParam.l
iImage.l
EndStructure
Procedure.l ShutDownComputer(CompName.s, MessageToUser.s, SecondsUntilShutdown.l, ForceAppsClosed.l, RebootAfter.l)
ShutDown = InitiateSystemShutdown_(CompName, MessageToUser, SecondsUntilShutdown, ForceAppsClosed, RebootAfter)
ProcedureReturn ShutDown
EndProcedure
Procedure.l AbortShutdown(CompName.s)
AbortShutDown = AbortSystemShutdown_(CompName)
ProcedureReturn AbortShutDown
EndProcedure
; PureBasic Visual Designer v3.62
;- Window Constants
;
#Window_0 = 0
;- Gadget Constants
;
#Gadget_0 = 0
#Gadget_1 = 1
#Gadget_2 = 2
#Gadget_3 = 3
#Gadget_4 = 4
#Gadget_5 = 5
#Gadget_6 = 6
#Gadget_7 = 7
#Gadget_8 = 8
#Gadget_9 = 9
#Gadget_10 = 10
#Gadget_11 = 11
#Gadget_12 = 12
Procedure.s GetBrowseNetworkWorkstation()
BI.BROWSEINFOS
pidl.l
sPath.s
pos.l
hwnd = WindowID(#Window_0)
If SHGetSpecialFolderLocation_(hwnd, #CSIDL_NETWORK, @pidl) = #ERROR_SUCCESS
BI\hwndOwner = hwnd
BI\pidlRoot = pidl
BI\pszDisplayName = Space(256)
BI\lpszTitle = "Select a network computer."
BI\ulFlags = #BIF_BROWSEFORCOMPUTER
If SHBrowseForFolder_(BI) <> 0
Name.s = "\\"+ BI\pszDisplayName
ProcedureReturn Name
EndIf
CoTaskMemFree_(@pidl)
EndIf
EndProcedure
Procedure Open_Window_0()
If OpenWindow(#Window_0, 216, 0, 302, 365, #PB_Window_SystemMenu | #PB_Window_SizeGadget | #PB_Window_TitleBar , "ShutGUI")
If CreateGadgetList(WindowID())
TextGadget(#Gadget_0, 20, 20, 80, 20, "ComputerName:")
StringGadget(#Gadget_1, 110, 20, 120, 20, "")
ButtonGadget(#Gadget_2, 250, 20, 30, 20, "...")
Frame3DGadget(#Gadget_3, 30, 60, 250, 80, "Optionen")
CheckBoxGadget(#Gadget_4, 60, 80, 190, 20, "Anwendungen forciert beenden")
CheckBoxGadget(#Gadget_5, 60, 110, 190, 20, "Neustart nach Herunterfahren")
TextGadget(#Gadget_6, 30, 160, 220, 20, "zu sendende Nachricht (127 Zeichen max)")
StringGadget(#Gadget_7, 30, 190, 250, 80, "", #PB_String_MultiLine|#ES_AUTOVSCROLL)
TextGadget(#Gadget_8, 60, 280, 80, 20, "Delay (Sek.):")
StringGadget(#Gadget_9, 150, 277, 30, 20, "30")
ButtonGadget(#Gadget_10, 20, 310, 80, 30, "Herunterfahren")
ButtonGadget(#Gadget_11, 120, 310, 80, 30, "Abbrechen")
ButtonGadget(#Gadget_12, 210, 310, 80, 30, "Beenden")
EndIf
EndIf
EndProcedure
Open_Window_0()
SetGadgetState(#Gadget_5, 1)
Repeat
Event = WaitWindowEvent()
If Event = #PB_EventCloseWindow
quit = 1
ElseIf Event = #PB_Event_Gadget
Select EventGadgetID()
Case 2
SetGadgetText(#Gadget_1, GetBrowseNetworkWorkstation())
Case 10
Name.s = GetGadgetText(#Gadget_1)
message.s = GetGadgetText(#Gadget_7)
pause.s = GetGadgetText(#Gadget_9)
chkKillApps.l = GetGadgetState(#Gadget_4)
chkReboot.l = GetGadgetState(#Gadget_5)
If Name = ""
MessageRequester("Client wählen", "Es wurde kein Client ausgewählt. ", #MB_ICONEXCLAMATION)
Else
goShutdown = ShutDownComputer(Name, message, Val(pause), chkKillApps, chkReboot)
If goShutdown = 1
MessageRequester("Kommando erfolgreich", "Herunterfahren erfolgreich eingeleitet für " + Name + ". " + Chr(13) + "Der Client wird heruntergefahren in " + pause + " Sekunden. ", #MB_ICONINFORMATION)
ElseIf goShutdown = 0
MessageRequester("Fehler", "Herunterfahren nicht möglich für " + Name + ". Mögliche Ursachen: " + Chr(13) + Chr(13) + "1. ClientName falsch geschrieben." + Chr(13) + "2. Der Computer ist kein Window NT-Client." + Chr(13) + "3. Sie haben nicht die erforderlichen Rechte." + Chr(13) + "4. Der Client kann im Netz nicht gefunden werden.", #MB_ICONEXCLAMATION)
EndIf
EndIf
Case 11
Name.s = GetGadgetText(#Gadget_1)
If Name = ""
MessageRequester("Client wählen", "Es wurde kein Client ausgewählt", #MB_ICONSTOP)
Else
cancelShutdown = AbortShutdown(Name)
If cancelShutdown = 1
MessageRequester("Abbruch erfolgreich", "Herunterfahren erfolgreich abgebrochen für " + Name + ".", #MB_ICONINFORMATION)
ElseIf cancelShutdown = 0
MessageRequester("Abbruch unmöglich", "Abbruch nicht möglich für " + Name + ". Mögliche Ursachen: " + Chr(13) + Chr(13) + "1. ClientName falsch geschrieben." + Chr(13) + "2. Der Computer ist kein Window NT-Client." + Chr(13) + "3. Sie haben nicht die erforderlichen Rechte." + Chr(13) + "4. Der Client kann im Netz nicht gefunden werden." + Chr(13) + "5. Zu spät.", #MB_ICONEXCLAMATION)
EndIf
EndIf
Case 12
quit = 1
EndSelect
EndIf
Until quit
End
No programming language is perfect. There is not even a single best language.
There are only languages well suited or perhaps poorly suited for particular purposes. Herbert Mayer
There are only languages well suited or perhaps poorly suited for particular purposes. Herbert Mayer
or have a look here : http://www.purearea.net/pb/CodeArchiv/English.html#9
No programming language is perfect. There is not even a single best language.
There are only languages well suited or perhaps poorly suited for particular purposes. Herbert Mayer
There are only languages well suited or perhaps poorly suited for particular purposes. Herbert Mayer
Thanks for the fast reply, but...
the problem is that you must select the other computer by a dialog window. I need all the IP in the LAN without any user request. (just a list or something)...
It can be done with a batch:
Net View > NetTemp.txt
Exit
and then you can get the data from the NetTemp.txt, but i don't want to use old Win95 Batch Programms to write IPs in a Text file. I need something like Net View as an API (or what ever) command.
Any idea about that ?
It can be done with a batch:
Net View > NetTemp.txt
Exit
and then you can get the data from the NetTemp.txt, but i don't want to use old Win95 Batch Programms to write IPs in a Text file. I need something like Net View as an API (or what ever) command.
Any idea about that ?
Re: Thanks for the fast reply, but...
Have you ever (you'r german) read the actually CT ?Motu23 wrote:but i don't want to use old Win95 Batch Programms to write IPs in a Text file.
Batch-programming is not restricted to W89, and also available under XP.
Use the Capture-Pipes snippet i wrote in the Tips&tricks or study the WinAPI.Motu23 wrote: I need something like Net View as an API (or what ever) command.
Any idea about that ?
Another solution is to ping every IP and Port
also there are snippets for that .
SPAMINATOR NR.1
Here's a simple example:
------------------------------
InitNetwork()
ExamineIPAddresses()
Repeat
rr=NextIPAddress()
If rr:a$=IPString(rr):EndIf
If Mid(a$,1,7)="192.168":LANIP$=a$:EndIf
Until rr=0
Debug LANIP$
------------------------------
Typically LAN addresses starts with 192.168
------------------------------
InitNetwork()
ExamineIPAddresses()
Repeat
rr=NextIPAddress()
If rr:a$=IPString(rr):EndIf
If Mid(a$,1,7)="192.168":LANIP$=a$:EndIf
Until rr=0
Debug LANIP$
------------------------------
Typically LAN addresses starts with 192.168
AMD 1.8 - 512mb - ATI All-In-Wonder Radeon 9000 pro - W2k Pro
BASIC programmers never die, they just return without gosub.
BASIC programmers never die, they just return without gosub.
That's a *really* big assumption. There are several "private" ip address classes..Typically LAN addresses starts with 192.168
10.0.0.0 - 10.255.255.255
172.16.0.0 - 172.31.255.255
192.168.0.0 - 192.168.255.255
... and some people may use public IPs for their workstations so that opens up every other IP as a possiblility
What you might think about is getting the IP of the computer running the program, use the first two or three octets from that to do the scanning. It's far from perfect but better than hard coding addresses or partial addresses in there I think.
Good luck!
-Mitchell
Check out kBilling for all your billing software needs!
http://www.k-billing.com
Code Signing / Authenticode Certificates (Get rid of those Unknown Publisher warnings!)
http://codesigning.ksoftware.net
Check out kBilling for all your billing software needs!
http://www.k-billing.com
Code Signing / Authenticode Certificates (Get rid of those Unknown Publisher warnings!)
http://codesigning.ksoftware.net



