Author Topic: IP address...  (Read 13623 times)

0 Members and 1 Guest are viewing this topic.

Patrick_35

  • Guest
Re: IP address...
« Reply #30 on: October 26, 2006, 05:26:19 PM »
Very nice

I suspected well that one could work with the activex, but I had not arrived yet there

@+

ronjonp

  • Needs a day job
  • Posts: 7529
Re: IP address...
« Reply #31 on: June 25, 2007, 12:36:46 PM »
Here ya go.

Written quickly. This means there are errors I failed to find | fix. Please follow prudent backup / testing methodologies. No warranty for any particular use is stated or implied. Use at your own risk.

Code: [Select]
(defun FindItemInFile ( PredicateFunction filename / handle item )

    ;;  © 2005 Michael Puckett

    (if
        (and
            (eq 'str (type filename))
            (setq handle (open filename "r"))
        )
        (vl-catch-all-apply
           '(lambda ( / stream )
                (while (setq stream (read-line handle))
                    (cond
                        (   (PredicateFunction stream)
                            (close handle)
                            (setq item stream)
                            (exit)
                        )
                    )
                )
                (close handle)
            )
        )
    )
    item
)


(defun HiddenShellInPgpFile ( / filepath filebackup handle )

    ;;  © 2005 Michael Puckett

    (or
        (FindItemInFile
            (lambda (stream)
                (wcmatch
                    (strcase (vl-string-trim " \t\n" stream))
                    "HIDDENSHELL`,`,4`,`*OS COMMAND:`,"
                )
            )
            (setq filepath (findfile "acad.pgp"))
        )
        (and
            filepath
            (setq filebackup (vl-filename-mktemp filepath))
            (vl-file-copy filepath filebackup)
            (setq handle (open filepath "a"))
            (princ "\nHiddenShell,,4,*OS Command:,\n" handle)
            (null (close handle))
            (setvar "re-init" 16)
        )
    )
)


(defun HiddenShell ( statement / cmdecho )

    ;;  © 2005 Michael Puckett

    (cond
        (
            (HiddenShellInPgpFile)
            (setq cmdecho (getvar "cmdecho"))
            (setvar "cmdecho" 0)
            (command "HiddenShell" statement)
            (setvar "cmdecho" cmdecho)
            t
        )
    )
)


(defun GetIPAddress ( / tempfile ipAddressStream ipAddress )

    ;;  © 2005 Michael Puckett

    (if
        (and

            (HiddenShell
                (strcat "ipconfig.exe > "
                    (setq tempfile
                        (vl-filename-mktemp "ipconfig.txt")
                    )
                )
            )

            (setq ipAddressStream
                (FindItemInFile
                    (lambda (stream)
                        (wcmatch
                            (strcase stream)
                            "*IP ADDRESS*"
                        )
                    )
                    tempfile
                )
            )

        )

        (setq ipAddress
            (vl-string-trim " "
                (vl-list->string
                    (cdr
                        (member 58
                            (vl-string->list ipAddressStream)
                        )
                    )
                )
            )
        )
    )

    (if tempfile (vl-file-delete tempfile)) ;; clean up our mess

    ipAddress

)
Cheers.

:D

MP,

I made a small addition to your function so it would return the IP address on a Vista computer  :-):

Code: [Select]
(defun GetIPAddress (/ tempfile ipAddressStream ipAddress)
  ;;  © 2005 Michael Puckett
  (if
    (and
      (HiddenShell
(strcat "ipconfig.exe > "
(setq tempfile
       (vl-filename-mktemp "ipconfig.txt")
)
)
      )
      (setq ipAddressStream
     (FindItemInFile
       (lambda (stream)
(or
   (wcmatch
     (strcase stream)
     "*IP ADDRESS*"
   )
   (wcmatch
     (strcase stream)
     "*IPV4 ADDRESS*"
   )
)
       )
       tempfile
     )
      )
    )
     (setq ipAddress
    (vl-string-trim
      " "
      (vl-list->string
(cdr
  (member 58
  (vl-string->list ipAddressStream)
  )
)
      )
    )
     )
  )
  (if tempfile
    (vl-file-delete tempfile)
  )
  ipAddress
)

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: IP address...
« Reply #32 on: February 27, 2009, 04:21:32 PM »
<Why all the interest (in particular guest views, sometimes 4 or more at a time) in this thread today?/weird>
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

ronjonp

  • Needs a day job
  • Posts: 7529
Re: IP address...
« Reply #33 on: February 27, 2009, 05:17:17 PM »
<Why all the interest (in particular guest views, sometimes 4 or more at a time) in this thread today?/weird>

I don't know...but after looking at my modification...I'd take out the OR (wcmatch (strcase stream) "*IP*ADDRESS*")  :-D

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

gskelly

  • Newt
  • Posts: 185
Re: IP address...
« Reply #34 on: February 28, 2009, 05:50:01 PM »
<Why all the interest (in particular guest views, sometimes 4 or more at a time) in this thread today?/weird>

I think it was referred to via a link in a message on WAUN... (not 100% I remember which list the message was from).
Bricscad v12

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: IP address...
« Reply #35 on: March 01, 2009, 12:31:03 AM »
<Why all the interest (in particular guest views, sometimes 4 or more at a time) in this thread today?/weird>

I think it was referred to via a link in a message on WAUN...

QFT
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.