TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: Andrea on March 02, 2005, 10:00:27 PM

Title: IP address...
Post by: Andrea on March 02, 2005, 10:00:27 PM
ok..

there is another one..
Can we get the IP address in LISP ??

some command like (vl-getip)  ??


 :lol:
Title: IP address...
Post by: TR on March 02, 2005, 10:13:29 PM
Not 100% sure but try doslib.

http://www.mcneel.com/doslib.htm
Title: IP address...
Post by: MP on March 03, 2005, 12:30:02 AM
I've been using a small dll I wrote years ago in VB that encapsulates a number of network related API calls. I can call it from Visual LISP.

See www.vbnet.mvps.org (http://www.vbnet.mvps.org/code/network/getadaptersinfo-localipaddress.htm).
Title: IP address...
Post by: Andrea on March 03, 2005, 08:24:14 AM
Quote from: Tim Riley
Not 100% sure but try doslib.

http://www.mcneel.com/doslib.htm


Yes, I know...
but i forgot to tell that i don'T want to load an ARX just for adding a simple line in LISp...
Title: IP address...
Post by: Andrea on March 03, 2005, 08:27:46 AM
Quote from: MP
I've been using a small dll I wrote years ago in VB that encapsulates a number of network related API calls. I can call it from Visual LISP.

See www.vbnet.mvps.org (http://www.vbnet.mvps.org/code/network/getadaptersinfo-localipaddress.htm).



sorry..but same thing with DLL...
just need to know if there is a command or variable in LISP.
Title: IP address...
Post by: MP on March 03, 2005, 08:56:47 AM
(http://www.theswamp.org/screens/mp/rbtl.png)








:)
Title: IP address...
Post by: Andrea on March 03, 2005, 06:00:01 PM
Quote from: MP
(http://www.theswamp.org/screens/mp/rbtl.png)


:)




Sorry,...but don't want to load anything else that the LISP file..
so in VBA need to load VBA module.. (VBALOAD)   see ?
Title: IP address...
Post by: kozmos on March 04, 2005, 08:18:37 AM
you can add a .dvb file into VLX as resource file while compile and then load the dvb in runtime
Title: IP address...
Post by: SMadsen on March 04, 2005, 10:04:32 AM
Here's a lisp you can tweak into getting some IP's

Code: [Select]
(defun IPReport (/ ws fn fp ln)
  (setq ws (vlax-get-or-create-object "WScript.Shell")
        fn (strcat (getenv "SystemDrive") "\\ipid.txt"))

  (vlax-invoke-method ws "Run" (strcat "%comspec% /c ipconfig /all >> " fn))

  (cond ((findfile fn)
         (setq fp (open fn "r"))
         (while (setq ln (read-line fp))
           (princ ln)
           (terpri)
         )
         (close fp)
         (vl-file-delete fn)
        )
  )
  (vlax-release-object ws)
  (princ)
)
Title: IP address...
Post by: MP on March 04, 2005, 01:43:29 PM
Good one Stig, I forgot about that technique.

Note: If one uses the redirected ipconfig output be careful when parsing the ipaddress -- the ipconfig output format changes slightly between Windows versions.

This works under Windows 2000, not sure about other Windows versions:

Code: [Select]
(defun GetIPAddress ( / cmdecho tempfile handle stream result  )

    (setq cmdecho (getvar "cmdecho"))
    (setvar "cmdecho" 0)

    (command ".shell"
        (strcat "ipconfig > "
            (setq tempfile
                (vl-filename-mktemp "ipconfig.txt")
            )            
        )
    )
   
    (setvar "cmdecho" cmdecho)
   
    (cond
        (   (setq handle (open tempfile "r"))
            (vl-catch-all-apply
               '(lambda ()
                    (while (setq stream (read-line handle))
                        (cond
                            (   (wcmatch
                                    (setq stream (strcase stream))
                                    "*IP ADDRESS*"
                                )
                                (setq result stream)
                                (exit)
                            )    
                        )
                    )
                )
            )    
            (close handle)
        )    
    )
   
    (if result
        (vl-string-trim " "
            (vl-list->string
                (cdr
                    (member 58
                        (vl-string->list result)
                    )
                )
            )    
        )    
    )    
)
Title: IP address...
Post by: MP on March 04, 2005, 01:49:25 PM
A friend just confirmed it works under Windows XP Pro.
Title: IP address...
Post by: SMadsen on March 04, 2005, 03:10:45 PM
Somehow I couldn't get ipconfig to write to a file with the wscript method. That's why I did the %comspec% call. It worked.
Of course, the SHELL command hovered right over my head without ever touching down  Heh
Thanks for the reminder, Michael.
Title: IP address...
Post by: MP on March 04, 2005, 03:15:39 PM
Funny, when I saw the use of wscript I thought "That's great, no more momentary dos window flash", but it still appears, so I thought shell would be just as effective; maybe a smidge faster. Still wscript, file system object etc. are good tools for the box.

Thanks for the initial idea Stig, have a great weekend.

:)
Title: IP address...
Post by: Andrea on March 05, 2005, 07:49:02 PM
hey...this is cool..

but how can i run this witout the DOS screen ?
Title: IP address...
Post by: Kerry on March 05, 2005, 08:08:03 PM
Not really off topic ..

Has anyone had difficulty using WScript with regard to Virus Scanners ??
Title: IP address...
Post by: MP on March 05, 2005, 08:56:17 PM
You mean like this?

(http://www.theswamp.org/screens/mp/wscriptalert.png)

I was able to get the ipaddress using wmi but when I tried to write it out to a temp file using the File System Object ... tada. I'm still working on it (i.e. I refuse to be beat by a dumb ol' puter).

Are you trying something similar?

:D
Title: IP address...
Post by: Jeff_M on March 05, 2005, 09:06:29 PM
Over at the autodesk.autocad.customization newsgroup, Thomas Smith posted a small routine that accesses the registry and reports the IP address. It is in a thread entitled, oddly enough, "IP Address" that was started on December 10, 2003. I just tested it on my WinXP Home laptop and it returned the proper value. You might want to look at it. He did post a few attempts, make sure to grab the last one.

I didn't repost it here, as I'm unsure of the legality and/or ethics of doing such a thing.
Title: IP address...
Post by: MP on March 05, 2005, 09:16:25 PM
What, and take all the fun out of it?

Genuine thanks Jeff, but I'm having fun researching this -- copying existing code would be snoozeville. There's buckets of free info at MSDN. Just enough to make the task interesting but not wheel inventing.

:D

'Course, my MSDN membership dues weren't cheap.
Title: IP address...
Post by: Kerry on March 05, 2005, 09:24:24 PM
Quote from: MP
You mean like this?
:D


Yep.

I have used the FSO a lot, mainly 'cause of the speed.

I've been able to control my local scanner enviromment no problems, but a couple of my clients have had a bit more trouble ... some scanners don't provide the same selectable options regarding "ignoring" certain applications.
I need to do a bit of study on this when the swirling waters subside a little.


added:
interesting vbs name !!
hehehe
Title: IP address...
Post by: Jeff_M on March 05, 2005, 09:37:20 PM
Quote from: MP
What, and take all the fun out of it?

Not my intent at all, Michael. In fact I plan on playing around with it some myself. My post was supposed to have been directed towards Andrea since it seemed like they wanted  something to work with now, it's just that Kerry and you manged to post while I was composing mine.... :?

So, carry on with your pursuit of knowledge...  :twisted:

edited in response to others' notification of Andrea's gender, which is the way I was going to post originally...my apologies to Andrea...
Title: IP address...
Post by: MP on March 05, 2005, 10:43:01 PM
Quote from: Jeff_M
Not my intent at all, Michael. In fact I plan on playing around with it some myself. My post was supposed to have been directed towards Andrea since it seemed like she wanted  something to work with now, it's just that Kerry and you manged to post while I was composing mine.... :?

I may be mistaken, but I thought Andrea was a >he<. :oops:

Quote from: Jeff_M
So, carry on with your pursuit of knowledge...

Indeed! You too Jeff. :lol:

Quote from: Kerry
interesting vbs name !! hehehe

Create Retrieve Update Destroy.

Moo ha ha ha. :twisted:
Title: IP address...
Post by: daron on March 05, 2005, 11:35:18 PM
Ahem!!! Jeff??? Andrea is a he, not a she.



Carry-on!
Title: IP address...
Post by: MP on March 06, 2005, 11:41:46 AM
After trying a number of avenues it suddenly dawned on me ...

... if you add this line to your acad.pgp file:

Code: [Select]
HiddenShell,,4,*OS Command:,
This code will not flash the DOS window:

Code: [Select]
<See next post>
:D

Well off to church, catch ya later.

Edit: Removed code; superfluous given next post.
Title: IP address...
Post by: MP on March 06, 2005, 08:20:40 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
Title: Re: IP address...
Post by: ronjonp on October 25, 2006, 03:24:31 PM
Thanks for this function MP. I can use this :)
Title: Re: IP address...
Post by: MP on October 25, 2006, 04:02:03 PM
<blink> Thank you for taking the time to say so Ron!
Title: Re: IP address...
Post by: Andrea on October 26, 2006, 10:15:06 AM
Ahem!!! Jeff??? Andrea is a he, not a she.



Carry-on!

thanks Daron. :lmao:
Title: Re: IP address...
Post by: It's Alive! on October 26, 2006, 03:24:51 PM
Here's one

Code: [Select]
(defun ipaddress (/ item meth1 meth2 ml s wmi)
  (vl-load-com)
  (setq ml '()
WMI (vlax-create-object "WbemScripting.SWbemLocator")
meth1 (VLAX-INVOKE WMI 'ConnectServer nil nil nil nil nil nil nil nil)
meth2 (vlax-invoke meth1 'ExecQuery (strcat "Select IPAddress from Win32_NetworkAdapterConfiguration"))
S (vlax-for item meth2 (setq ml (append
  (vlax-get item 'IPAddress)
  ml
)
       )
  )
  )
  (vlax-release-object meth1)
  (vlax-release-object meth2)
  (vlax-release-object wmi)
  s
)

and
Code: [Select]
(defun ping (address / result)
  (setq result (Win32_PingStatus address))
  (if (= (cadr result) 0)
    t
    nil
  )
)
(defun Win32_PingStatus (Address / item meth1 meth2 s wmi x)
  (vl-load-com)
  (setq WMI (vlax-create-object "WbemScripting.SWbemLocator")
meth1 (VLAX-INVOKE WMI 'ConnectServer nil nil nil nil nil nil nil nil)
meth2 (vlax-invoke meth1 'ExecQuery (strcat "Select * From Win32_PingStatus where Address = '" address "'"))
S (vlax-for item meth2 (setq x (list (vlax-get item 'Address) (vlax-get item 'StatusCode) (vlax-get item 'ResponseTime))))
  )
  (vlax-release-object meth1)
  (vlax-release-object meth2)
  (vlax-release-object wmi)
  s
)
Title: Re: IP address...
Post by: It's Alive! on October 26, 2006, 03:31:53 PM
Now I am a Newt!  :lmao:
Title: Re: IP address...
Post by: Andrea on October 26, 2006, 04:12:11 PM
nice Daniel... :roll:


this was my old one..

Code: [Select]
(command "SH" "IPCONFIG > c:\\IPCFG.txt")
(setq f1 (open "c:\\IPCFG.txt" "r"))
(setq l1 (read-line f1))
(while l1
  (setq IPyes (vl-string-search "IP." l1))
  (if IPyes
    (progn
    (setq sp (vl-string-position (ascii ":") l1))
    (setq IPA (substr l1 (+ sp 3)))
  ))
(setq l1 (read-line f1))
)
(close f1)

(alert (strcat "IP Adress is : " IPA))





;;;;;;;;;;

(defun c:ping (/ pname f1 l1 IPyes)
(setq pname (getstring "Address : "))
(if pname
  (setq bfile (open "c:\\PIGNNAME.bat" "w"))
  (write-line (strcat "PING " pname " > c:\\PIGNNAME.txt") bfile)
 (close bfile)
(command pcommand)
(startapp "c:\\PIGNNAME.bat")
))
Title: Re: IP address...
Post by: Patrick_35 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

@+
Title: Re: IP address...
Post by: ronjonp 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
)
Title: Re: IP address...
Post by: MP 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>
Title: Re: IP address...
Post by: ronjonp 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
Title: Re: IP address...
Post by: gskelly 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).
Title: Re: IP address...
Post by: Kerry 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