Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

On each startup of the machine record the ip address of the machine with date and time

Posted on 2010-01-05
4
Medium Priority
?
211 Views
Last Modified: 2012-05-08
Hi,

On each startup of the machine record the ip address of the machine with date and time
I want help with a logon script that will record these data into a Machinename.txt file in a UNC.

User name , Ip Address,gateway,Date & Time,

Each machine should have seperate txt files
If UNC path not available do nothing rather than erroring on the client machine.

REgards
Sharath
0
Comment
Question by:bsharath
  • 2
  • 2
4 Comments
 
LVL 59

Expert Comment

by:Chris Bottomley
ID: 26178425
Try this as a script file that you can (hopefully) call as part of the startup.:

It saves to the temp folder as is but a different path can of course be used.

Chris
dim WshNetwork
Dim strUserName
Dim strComputerName
Dim strIPAddress
Dim strGateway
Dim fso
Dim outFile
dim strFileName

Set WshNetwork = WScript.CreateObject("WScript.Network")
strComputerName = WshNetwork.ComputerName
strUserName = WshNetwork.UserName
strIPAddress = GetIP()
strGateway = GetGateway()
'MsgBox "User Name: " & strUserName & VbCrLf & _
'		"IP Address: " & strIPAddress & VbCrLf & _
'		"Gateway: " & strGAteway & vbcrlf & _
'		"DTG: " & Now

	Set fso = CreateObject("Scripting.FileSystemObject")
  	strfilename = fso.GetSpecialFolder(2) & "/" & strComputerName & ".txt"
  	Set outFile = fso.OpenTextFile( strFileName, 8, True)
	outfile.WriteLine("User Name: " & strUserName)
	outfile.WriteLine("IP Address: " & strIPAddress)
	outfile.WriteLine("Gateway: " & strGAteway)
	outfile.WriteLine("DTG: " & Now)
	outfile.Close
  	


Function GetIP()
  Dim ws : Set ws = CreateObject("WScript.Shell")
  Dim fso : Set fso = CreateObject("Scripting.FileSystemObject")
  Dim TmpFile : TmpFile = fso.GetSpecialFolder(2) & "/ip.txt"
  Dim ThisLine, IP
  If ws.Environment("SYSTEM")("OS") = "" Then
    ws.run "winipcfg /batch " & TmpFile, 0, True
  Else
    ws.run "%comspec% /c ipconfig > " & TmpFile, 0, True
  End If
  With fso.GetFile(TmpFile).OpenAsTextStream
    Do While NOT .AtEndOfStream
      ThisLine = .ReadLine
      If InStr(ThisLine, "Address") <> 0 Then IP = Mid(ThisLine, InStr(ThisLine, ":") + 2)
    Loop
    .Close
  End With
  'WinXP (NT? 2K?) leaves a carriage return at the end of line
  If IP <> "" Then
    If Asc(Right(IP, 1)) = 13 Then IP = Left(IP, Len(IP) - 1)
  End If
  GetIP = IP
  fso.GetFile(TmpFile).Delete  
  Set fso = Nothing
  Set ws = Nothing
End Function

Function GetGateway()
  Dim ws : Set ws = CreateObject("WScript.Shell")
  Dim fso : Set fso = CreateObject("Scripting.FileSystemObject")
  Dim TmpFile : TmpFile = fso.GetSpecialFolder(2) & "/ip.txt"
  Dim ThisLine, IP
  If ws.Environment("SYSTEM")("OS") = "" Then
    ws.run "winipcfg /batch " & TmpFile, 0, True
  Else
    ws.run "%comspec% /c ipconfig > " & TmpFile, 0, True
  End If
  With fso.GetFile(TmpFile).OpenAsTextStream
    Do While NOT .AtEndOfStream
      ThisLine = .ReadLine
      If InStr(ThisLine, "Gateway") <> 0 Then IP = Mid(ThisLine, InStr(ThisLine, ":") + 2)
    Loop
    .Close
  End With
  'WinXP (NT? 2K?) leaves a carriage return at the end of line
  If IP <> "" Then
    If Asc(Right(IP, 1)) = 13 Then IP = Left(IP, Len(IP) - 1)
  End If
  GetGateway = IP
  fso.GetFile(TmpFile).Delete  
  Set fso = Nothing
  Set ws = Nothing
End Function

Open in new window

0
 
LVL 11

Author Comment

by:bsharath
ID: 26178556
Thanks
Where should i change the path to UNC
Can i get the data into one row for each time
0
 
LVL 59

Accepted Solution

by:
Chris Bottomley earned 2000 total points
ID: 26178622
Modified for a single line output and see the line:

        strfilename = "c:\deleteme\" & strComputerName & ".txt"

to edit for the UNC path

Chris
dim WshNetwork
Dim strUserName
Dim strComputerName
Dim strIPAddress
Dim strGateway
Dim fso
Dim outFile
dim strFileName

Set WshNetwork = WScript.CreateObject("WScript.Network")
strComputerName = WshNetwork.ComputerName
strUserName = WshNetwork.UserName
strIPAddress = GetIP()
strGateway = GetGateway()
'MsgBox "User Name: " & strUserName & VbCrLf & _
'		"IP Address: " & strIPAddress & VbCrLf & _
'		"Gateway: " & strGAteway & vbcrlf & _
'		"DTG: " & Now

	Set fso = CreateObject("Scripting.FileSystemObject")
  	strfilename = "c:\deleteme\" & strComputerName & ".txt"
  	Set outFile = fso.OpenTextFile( strFileName, 8, True)
	outfile.WriteLine("User Name: " & strUserName & " | " & _
		"IP Address: " & strIPAddress  & " | " & _
		"Gateway: " & strGateway  & " | " & _
		"DTG: " & Now)
	outfile.Close
  	


Function GetIP()
  Dim ws : Set ws = CreateObject("WScript.Shell")
  Dim fso : Set fso = CreateObject("Scripting.FileSystemObject")
  Dim TmpFile : TmpFile = fso.GetSpecialFolder(2) & "/ip.txt"
  Dim ThisLine, IP
  If ws.Environment("SYSTEM")("OS") = "" Then
    ws.run "winipcfg /batch " & TmpFile, 0, True
  Else
    ws.run "%comspec% /c ipconfig > " & TmpFile, 0, True
  End If
  With fso.GetFile(TmpFile).OpenAsTextStream
    Do While NOT .AtEndOfStream
      ThisLine = .ReadLine
      If InStr(ThisLine, "Address") <> 0 Then IP = Mid(ThisLine, InStr(ThisLine, ":") + 2)
    Loop
    .Close
  End With
  'WinXP (NT? 2K?) leaves a carriage return at the end of line
  If IP <> "" Then
    If Asc(Right(IP, 1)) = 13 Then IP = Left(IP, Len(IP) - 1)
  End If
  GetIP = IP
  fso.GetFile(TmpFile).Delete  
  Set fso = Nothing
  Set ws = Nothing
End Function

Function GetGateway()
  Dim ws : Set ws = CreateObject("WScript.Shell")
  Dim fso : Set fso = CreateObject("Scripting.FileSystemObject")
  Dim TmpFile : TmpFile = fso.GetSpecialFolder(2) & "/ip.txt"
  Dim ThisLine, IP
  If ws.Environment("SYSTEM")("OS") = "" Then
    ws.run "winipcfg /batch " & TmpFile, 0, True
  Else
    ws.run "%comspec% /c ipconfig > " & TmpFile, 0, True
  End If
  With fso.GetFile(TmpFile).OpenAsTextStream
    Do While NOT .AtEndOfStream
      ThisLine = .ReadLine
      If InStr(ThisLine, "Gateway") <> 0 Then IP = Mid(ThisLine, InStr(ThisLine, ":") + 2)
    Loop
    .Close
  End With
  'WinXP (NT? 2K?) leaves a carriage return at the end of line
  If IP <> "" Then
    If Asc(Right(IP, 1)) = 13 Then IP = Left(IP, Len(IP) - 1)
  End If
  GetGateway = IP
  fso.GetFile(TmpFile).Delete  
  Set fso = Nothing
  Set ws = Nothing
End Function

Open in new window

0
 
LVL 11

Author Comment

by:bsharath
ID: 26178758
Thank u Works perfect
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Deploying a Microsoft Access application in a Citrix environment is not difficult but takes a few steps. However, Citrix system people are often of little help, as they typically know next to nothing about Access. The script provided here will take …
In threads here at EE, each comment has a unique Identifier (ID). It is easy to get the full path for an ID via the right-click context menu. However, we often want to post a short link within a thread rather than the full link. This article shows a…
Learn the basics of lists in Python. Lists, as their name suggests, are a means for ordering and storing values. : Lists are declared using brackets; for example: t = [1, 2, 3]: Lists may contain a mix of data types; for example: t = ['string', 1, T…
The viewer will learn how to count occurrences of each item in an array.
Suggested Courses

578 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question