TheSwamp
Code Red => AutoLISP (Vanilla / Visual) => Topic started 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:
-
Not 100% sure but try doslib.
http://www.mcneel.com/doslib.htm
-
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).
-
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...
-
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.
-
(http://www.theswamp.org/screens/mp/rbtl.png)
:)
-
(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 ?
-
you can add a .dvb file into VLX as resource file while compile and then load the dvb in runtime
-
Here's a lisp you can tweak into getting some IP's
(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)
)
-
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:
(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)
)
)
)
)
)
)
-
A friend just confirmed it works under Windows XP Pro.
-
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.
-
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.
:)
-
hey...this is cool..
but how can i run this witout the DOS screen ?
-
Not really off topic ..
Has anyone had difficulty using WScript with regard to Virus Scanners ??
-
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
-
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.
-
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.
-
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
-
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...
-
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:
So, carry on with your pursuit of knowledge...
Indeed! You too Jeff. :lol:
interesting vbs name !! hehehe
Create Retrieve Update Destroy.
Moo ha ha ha. :twisted:
-
Ahem!!! Jeff??? Andrea is a he, not a she.
Carry-on!
-
After trying a number of avenues it suddenly dawned on me ...
... if you add this line to your acad.pgp file:
HiddenShell,,4,*OS Command:,
This code will not flash the DOS window:
<See next post>
:D
Well off to church, catch ya later.
Edit: Removed code; superfluous given next post.
-
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.
(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
-
Thanks for this function MP. I can use this :)
-
<blink> Thank you for taking the time to say so Ron!
-
Ahem!!! Jeff??? Andrea is a he, not a she.
Carry-on!
thanks Daron. :lmao:
-
Here's one
(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
(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
)
-
Now I am a Newt! :lmao:
-
nice Daniel... :roll:
this was my old one..
(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")
))
-
Very nice
I suspected well that one could work with the activex, but I had not arrived yet there
@+
-
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.
(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 :-):
(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
)
-
<Why all the interest (in particular guest views, sometimes 4 or more at a time) in this thread today?/weird>
-
<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
-
<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).
-
<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