[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 247
  • Last Modified:

Monitoring PING and responding

I wish to monitor either the pings or the fingers that the computer recieves, and, in response to a certain number, perform an action such as run a batch program. I am unsure as to which programming area to post this question under, so suggestions are welcome. Thank you...
0
dog78
Asked:
dog78
  • 4
  • 3
1 Solution
 
mcriderCommented:
Systems respond to ping using ICMP packets.  This is performed at the OS level and there is no way to count the number of pings that are received in VB.

Finger, on the other hand (no pun indended) operates on TCP port 79.  You could write an application that listens on port 79 and return the finger information, and keep track of the number of requests in your application.

Hope this helps...


cheers!
0
 
dog78Author Commented:
Do you know of any documentation regarding this task in VB? Also, I wish to have an event occur resulting from the reception of a finger.
0
 
mcriderCommented:
This quote is from the "Internet Protocols Handbook" by Dave Roberts, $35.99, Coriolis Group Books:

"The finger protocol is extremely simple. The finger client first makes contact with the finger server at the well-known port number. The client sends the server a query consisting of a single line of ASCII text followed by a CRLF end-of-line sequence.  The server returns one or more lines of text to the client and then closes the connection. After receiving the reply lines, the client closes the connection and the session is finished."

So for example the client sends:

    "mcrider" + VbCrLf

the server can respond:

    "Login: mcrider    Name: mike" + vbCrLf
    "Directory: /home/mcrider" + VbCrLf
    "No other information available" + VbCrLf


You can use the winsock control to perform the finger server function.  If you need an example of using the winsock control I have a very small chat server that can help you.


Cheers!
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
dog78Author Commented:
Well, lemmi just tell you what I'm trying to do and perhaps you know of a relatively simple way, even if it does not involve Finger or Ping.

I have one computer with constant internet access (via network) and I wish to have this computer perform routine tasks (via BAT file) at my request. I considered a scheduler, but my schedules dont follow any rules, so I'd have to be constantly re-scheduling. Therefore, I need a way of "signalling" this computer to execute the BAT file. I wish this to be a non-interfering transparent process, ie. I want the computer to be usable even when the processes are running.
0
 
mcriderCommented:
Here is a quick and dirty "restricted" Telnet server you can run in VB.  While the program is running, you can telnet into the system, login and do commands.

Just start a new project and add a winsock control to form1.  Set the Winsock1 INDEX PROPERTY to 0 and then paste the following code into the Declaration Section of Form1.

In the Winsock1_DataArrival event, there is a section where you can handle your own commands... Just put the command you want to handle as a case statement and then do whatever you want the command to do... shell a dos command, write information back to the client, it's pretty much up to you. Right now, the only commands handled are "QUIT" and "EXIT".

Don't forget to set the USERNAME and PASSWORD constants to whatever you want...



Cheers!


THE CODE:


Const USERNAME = "mcrider"
Const PASSWORD = "helloworld"
Private Sub Form_Load()
    Winsock1(0).LocalPort = 23
    Winsock1(0).Listen
End Sub
Private Sub Winsock1_Close(Index As Integer)
    Winsock1(Index).Close
    DoEvents
    Unload Winsock1(Index)
End Sub
Private Sub Winsock1_ConnectionRequest(Index As Integer, ByVal requestID As Long)
    Dim iVal As Integer
    iVal = Winsock1.Count
    Load Winsock1(iVal)
    With Winsock1(iVal)
        .Tag = "0"
        .Accept requestID
        .SendData "Login: "
        DoEvents
    End With
End Sub


Private Sub Winsock1_DataArrival(Index As Integer, ByVal bytesTotal As Long)
    Dim xCmd As String
    Dim xBuf As String
    Dim iVal As Long
   
    With Winsock1(Index)
        .GetData xBuf, vbString
        .Tag = .Tag + xBuf
        iVal = InStr(1, .Tag, vbCrLf)
        If Not iVal = 0 Then
            xBuf = Left$(.Tag, iVal - 1)
            Select Case Left$(xBuf, 1)
                Case "0"
                    If UCase$(Mid$(xBuf, 2)) = UCase$(USERNAME) Then
                        .Tag = "1"
                        .SendData "Password: "
                    Else
                        .Tag = "0"
                        .SendData "Login: "
                    End If
                Case "1"
                    If UCase$(Mid$(xBuf, 2)) = UCase$(PASSWORD) Then
                        .Tag = "2"
                        .SendData "Welcome " + USERNAME + vbCrLf + "COMMAND> "
                    Else
                        .Tag = "0"
                        .SendData "Login: "
                    End If
                Case "2"
                    xCmd = Mid$(xBuf, 2)
                    .Tag = "2" + Mid$(.Tag, iVal + 2)
                    '========================================================
                    'PUT CODE FOR YOUR VALID COMMANDS HERE AS CASE STATEMENTS
                    '========================================================
                    Select Case Trim$(UCase$(xCmd))
                        Case "QUIT", "EXIT"
                            .SendData "Good-bye!" + vbCrLf + vbCrLf
                            DoEvents
                            Winsock1_Close .Index
                            Exit Sub
                        Case Else
                            .SendData "Invalid Command: [" + xCmd + "]"
                    End Select
                    '========================================================
                    'END OF VALID COMMANDS
                    '========================================================
                    .SendData vbCrLf + "COMMAND> "
                Case Else
                    .Tag = "0"
                    .SendData "Login: "
            End Select
        End If
    End With
    DoEvents
End Sub
0
 
dog78Author Commented:
Thank you, this should serve well for my purposes.
0
 
mcriderCommented:
Glad I could help!

Cheers!
0

Featured Post

[Webinar] Improve your customer journey

A positive customer journey is important in attracting and retaining business. To improve this experience, you can use Google Maps APIs to increase checkout conversions, boost user engagement, and optimize order fulfillment. Learn how in this webinar presented by Dito.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now