WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

Network Related

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

Get IP MAC UDF


;***************************************************************************
;**Gets ip and mac information from current network card
;***************************************************************************
#DefineFunction GetTCPIPInfo_UDF(value)
      origdir        = DirGet()
		OutputFile     = StrCat (origdir, "IPCFG_TEMP.TXT")
		If WinVersion(4) == 4;WINNT	   
		   RunHideWait(Environment('COMSPEC'), '/c IPCONFIG /ALL >"%OutputFile%"')
		Else
		  RunHideWait('WINIPCFG', '/ALL /BATCH > "%OutputFile%"')
		Endif
		
		If !FileExist(OutputFile)
		     MessageTxt = StrCat ("TCP/IP parameters can't be determined.", @CRLF)
		     MessageTxt = StrCat (MessageTxt, @CRLF, "No data will be captured.", @CRLF)
		     Message (Caption, MessageTxt)
		     exit
		EndIf
		
		fs        = Filesize (OutputFile)
		buf       = BinaryAlloc(fs)
		BinaryRead(buf, OutputFile)
		;		
		; Grab value from file
		;
		lacptr = BinaryIndexEx(buf, 0, "Description", @FWDSCAN, 0)
		if lacptr==-1 
			 Message("Error","Unable to locate TCPIP Info! (Description)")
			 exit
		endif
		ptr  = BinaryIndexEx(buf, lacptr, value, @FWDSCAN, 0)
		if ptr==-1 
			 Message("Error","Unable to locate TCPIP Info! (Value)")
			 exit
		endif
		colonptr    = BinaryIndexEx(buf, ptr, ":", @FWDSCAN, 0)
		if colonptr==-1 
			 Message("Error","Unable to locate TCPIP Info! (Colon)")
			 exit
		endif
		crlfptr     = BinaryIndexEx(buf, ptr, @CRLF, @FWDSCAN, 0)
		if crlfptr==-1 
			 Message("Error","Unable to locate TCPIP Info!(CRLF)")
			 exit
		endif
		Address  = BinaryPeekStr(buf, colonptr+2, crlfptr-colonptr-2)
		Address  = StrTrim(Address)
		BinaryFree (buf)
		FileDelete(OutputFile)
		return Address
#EndFunction

value = "Physical Address"
mac = GetTCPIPInfo_UDF(value)

value = "IP Address"
ip = GetTCPIPInfo_UDF(value)



handle = FileOpen("IP-MAC.txt", "WRITE")
FileWrite(handle, "Current User Infomation:            %curruser%")

;Workstation Report Section
;handle = FileOpen(saveas, "write")
FileWrite(handle, "")
FileWrite(handle,  "==================================================================")
FileWrite(handle, "                            Created by Dale")
FileWrite(handle, "                       Get IP Address -MAC Address")
FileWrite(handle, "")
FileWrite(handle,  "==================================================================")
FileWrite(handle, "")
FileWrite(handle, "Date:                     %date%")
FileWrite(handle, "-------------------------------------------------------------------")
FileWrite(handle, "")
FileWrite(handle, "")
FileWrite(handle, "TCPIP Information         %ip%")
FileWrite(handle, "MAC Address               %mac%")
FileClose(handle)
exit

Article ID:   W16252
File Created: 2004:08:04:14:08:52
Last Updated: 2004:08:04:14:08:52