Hello. I already have winsock server and client programs. i have one server and about 10 clients.
How do I list all the IP addresses of computers connected to the server? Can I also do this in the clients?
Printable View
Hello. I already have winsock server and client programs. i have one server and about 10 clients.
How do I list all the IP addresses of computers connected to the server? Can I also do this in the clients?
One way would be to shell out the netstat dos command and output its results to a textfile. Then read it back in to your app.
VB Code:
Option Explicit Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hWnd As Long, ByVal lpOperation As String, _ ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long Private Const SW_HIDE As Long = 0 Private Const SW_SHOWNORMAL As Long = 1 Private Const SW_SHOWMAXIMIZED As Long = 3 Private Const SW_SHOWMINIMIZED As Long = 2 Private Sub Command1_Click() 'If running XP then you can use the -ano switch. 'Also, if not running XP then the path to CMD.exe will be different. This can be dynamically obtained 'by using the GetSystemDirectory API ShellExecute Me.hWnd, "Open", "C:\Windows\System32\CMD.exe", " netstat -ano >C:\Ports.tmp", "C:\", SW_HIDE 'If running pre-XP then just -ao 'ShellExecute Me.hWnd, "Open", "C:\Windows\System32\CMD.exe", " netstat -ao >C:\Ports.tmp", "C:\", SW_HIDE 'ToDo: After process is completed, read the file back in. '... End Sub
how about this
orVB Code:
Private Sub socket_ConnectionRequest(Index As Integer, ByVal requestID As Long) Load Socket(Socket.UBound + 1) Socket(Socket.UBound).Accept requestID [COLOR=darkred]List1.AddItem "Connection request id " & requestID & " from " & [b]Socket(Index).RemoteHostIP[/b][/COLOR][b] [/B] End Sub
VB Code:
Private Sub ListIPs For i = Socket.LBound to Socket.UBound if socket(i).state = 7 then [COLOR=darkred]List1.AddItem "Connection " & i & [b]Socket(Index).RemoteHostIP[/b][/COLOR][b] [/B] next i End Sub
Thanks dlern and RobDog888!
RobDog888, I am concerned with my classmates. I don't think they will understand what you gave me. Hehe. But it's good! Thanks!
dlern, this is better because it is more straightforward.
Thanks everyone!