Author Topic: Ping test  (Read 1956 times)

0 Members and 1 Guest are viewing this topic.

Logan

  • Newt
  • Posts: 41
Ping test
« on: August 01, 2017, 02:50:56 PM »
Hello everyone.
Do you know a more elegant way to accomplish this task?
I see a small window to open in the Windows taskbar.

Code: [Select]
(defun c:pingtest (/ ping)
 
  (defun ping (adress / pingStatus objShell)
    (vl-load-com)
    (setq objShell (vlax-get-or-create-object "WScript.Shell"))
    (setq pingStatus
   (vl-catch-all-apply
     'vlax-invoke-method
     (list
       objShell
       "Run"
       (strcat "ping -n 1 " adress)
       6
       :vlax-true
     ) ;_ >list
   ) ;_ >vl-catch-all-apply
    ) ;_ >setq
    (vlax-release-object objShell)
    (gc)
    (cond
      (
       (= 0 pingStatus)
       (setq pingStatus t)
      )
      (
       (= 1 pingStatus)
       (setq pingStatus nil)
      )
      (
       (vl-catch-all-error-p pingStatus)
       (vl-catch-all-error-message pingStatus)
       (setq pingStatus nil)
      )
    ) ;_ >cond
  ) ;_ >defun

  (if (ping "www.theswamp.org")
    (princ "Status: online")
    (princ "Status: offline")
  ) ;_ >if
  (princ)
) ;_ >defun

Best regards
Luís Augusto

Lee Mac

  • Seagull
  • Posts: 12913
  • London, England
Re: Ping test
« Reply #1 on: August 01, 2017, 03:15:34 PM »
You could use WMI, e.g.:
Code - Auto/Visual Lisp: [Select]
  1. (defun ping ( hst / qry rtn srv wmi )
  2.     (vl-catch-all-apply
  3.        '(lambda ( / lst )
  4.             (setq wmi (vlax-create-object "wbemscripting.swbemlocator")
  5.                   srv (vlax-invoke wmi 'connectserver)
  6.                   qry (vlax-invoke srv 'execquery (strcat "SELECT * FROM Win32_PingStatus WHERE Address = '" hst "'"))
  7.             )
  8.             (vlax-for itm qry
  9.                 (vlax-for prp (vlax-get itm 'properties_)
  10.                     (setq lst (cons (cons (vlax-get prp 'name) (vlax-get prp 'value)) lst))
  11.                 )
  12.             )
  13.             (setq rtn (zerop (cdr (assoc "StatusCode" lst))))
  14.         )
  15.     )
  16.     (foreach obj (list qry srv wmi) (if obj (vlax-release-object obj)))
  17.     rtn
  18. )

Translated from Rob van der Woude's page.

Logan

  • Newt
  • Posts: 41
Re: Ping test
« Reply #2 on: August 01, 2017, 04:42:52 PM »
Thanks for adapting the code and sharing with us Lee Mac. I really appreciate your work.
The code works the way I need it.
Rob Van der Woude's website is very good and has great examples there. Thanks for sharing.

Luís  Augusto.

lamarn

  • Swamp Rat
  • Posts: 636
Re: Ping test
« Reply #3 on: August 02, 2017, 05:26:04 PM »
Having poor performance with AutoCAD in combination with some particular projects on part of our network. My guess is that AutoCAD is taking large portions to run the programm and there is little left for moving data. I'm curious if it would be possibe to use this to check network speed (inside / outside AutoCAD?).
Design is something you should do with both hands. My 2d hand , my 3d hand ..