Searching for server among my LAN
Hi,
I built a network application that do desktop monitoring and many other actions, I'm trying to improve the connection possibility, how the client will find the server, i know that LAN IP address is static in 1st 3 parts 192.168.1.NNN where is NNN is a dynamic part from0 to 255.
I'm trying to build my client to find the server without providing the server IP.
so when client start for the first time it will search for server on port 540 and IP address will be placed in for loop
so the connect method will placed in for loop
for(byte x=0; x<=255; x++)
{
connect(540,"192.168.1." + x);
}
by using this method i will try to connect to my server if server is online its supposed that client find server.
is this a successful method, i need your opinion on this, is there a faster method, the connect method in c# take a while before telling me that connection refused, so searching from 0 to 255 will take time!!!
please help me in this.
Thanks in advanced for your help.
Re: Searching for server among my LAN
Quote:
i know that LAN IP address is static in 1st 3 parts 192.168.1.NNN where is NNN is a dynamic part from0 to 255.
Only in a class C network
Re: Searching for server among my LAN
Re: Searching for server among my LAN
look at what wikipedia has to say about this
Re: Searching for server among my LAN
i don't figure it out,
my LAN contain 30 computers the fixed part of their ip is 192.168.1 the dynamic part start from 1 to 30
my server placed in any computer, i need to find it. so i will have to connect from 1 to 30 the one that accept the connection on specific port it will be the pc that contain my server.
that what i mean, like a port scanner. but a fixed port.
Re: Searching for server among my LAN
I thought you wanted something global, not just for your network.
Anyway it seems that in Windows XP their is a tool called PathPing
I think it might be helpful if there was a .NET class or library that can do what it does.
If you try using it, the "Hop" number 1 is your local server
Re: Searching for server among my LAN
thanks,
but pathping and ping, just take as a param the ip
i need to know if my app running there or not so i need a port too
so ping 192.168.1.2 on port 198
if result returned then server is running. server mean that my app is running in that machine.
Re: Searching for server among my LAN
I do the following code in VB6.
Its work for the 1st time but if i repeat the code again it dosn't work. untill i restart both the server and the detector.
Code:
Private Sub Command1_Click()
List.Clear
Reload
Command1.Enabled = False
Dim SocketsCount As Integer
For SocketsCount = Mid(T1, InStrRev(T1, ".") + 1, Len(T1.Text)) To Mid(T2, InStrRev(T2, ".") + 1, Len(T2.Text))
Load Winsock(SocketsCount)
L1.Caption = "Loading and Connecting Socket [ " & SocketsCount & " : " & Mid(T2, InStrRev(T2, ".") + 1, Len(T2.Text)) & " ]"
Dim IP As String: IP = Mid(T1, 1, InStrRev(T1, ".")) & SocketsCount
Winsock(SocketsCount).Protocol = sckTCPProtocol
Winsock(SocketsCount).Close
Winsock(SocketsCount).Connect IP, Val(T3.Text)
Winsock(SocketsCount).Tag = IP
DoEvents
Next SocketsCount
Command1.Enabled = True
End Sub
Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
ExitProcess (0)
End Sub
Private Sub Winsock_Connect(Index As Integer)
List.AddItem "- " & Winsock(Index).RemoteHost & " Connected."
Winsock(Index).SendData "PING"
DoEvents
Winsock(Index).Close
End Sub
Sub Reload()
Dim X As Integer
For X = 1 To Winsock.UBound
Winsock(X).Close
Unload Winsock(X)
Next X
End Sub
sorry i wrote the code in VB6 cause it faster to code it than c#
Re: Searching for server among my LAN
Do you have active directory setup? Why not just make a group policy that forces that program to run all the time, and don't give user rights to turn it off?
After that, set you monitoring program on your client to send SNMP messages every so often and have triggers set to do stuff based on the traps. This changes the scheme to passive monitoring, so you don't have to scan your network. You can even write your client app to send a message if it closes.
Re: Searching for server among my LAN
thanks a lot for ur advice :)
but is there a chance to implement my idea, as searching LAN for a server is needed, many LAN applications don't need to setup the client to know server address it discover it automaticaly, by searching for a listeaners.
the code i past is working but, if i click the Command1 twice, it show the result at first time, but if i change port and search, nothing found!!! its supposed that sockets object unloaded, so it should connect to new server using new ports!!.
any idea!!
Thanks alot
Re: Searching for server among my LAN
thanks a lot for ur advice :)
but is there a chance to implement my idea, as searching LAN for a server is needed, many LAN applications don't need to setup the client to know server address it discover it automaticaly, by searching for a listeaners.
the code i past is working but, if i click the Command1 twice, it show the result at first time, but if i change port and search, nothing found!!! its supposed that sockets object unloaded, so it should connect to new server using new ports!!.
any idea!!
Thanks alot
Re: Searching for server among my LAN
Re: Searching for server among my LAN
Hi,
Thanks for ur post, but what is the use of this SW, i think its a tracer SW.
i didn't figure out the relation between my app and that sw.
thanks
Re: Searching for server among my LAN
it called a packet sniffer, you will probably need to be on a hub for it to work fully. However, you can see all the physicall packets entering and leaving your box. This will allow you to debug your program.
You might need to read up on a TCP/IP packets.
Re: Searching for server among my LAN
thanks a lot. i will try it.