Option Explicit
Sub User_Log_Record()
Dim ip_1$, j, strcomputer, objwmi, coliP, IP, computer_name, i
Workbooks.Open "D:\user_log.xlsx"
Windows("user_log.xlsx").Activate
Application.ScreenUpdating = False
j = 1
Do While Cells(j, 1) <> ""
j = j + 1
Windows("user_log.xlsx").Visible = False
strcomputer = "."
Set objwmi = GetObject("winmgmts:\\" & strcomputer & "\root\cimv2")
Set coliP = objwmi.ExecQuery _
("Select * from Win32_NetworkAdapterConfiguration where IPEnabled=TRUE")
For Each IP In coliP
If Not IsNull(IP.IPAddress) Then
ip_1 = IP.IPAddress(i) 'get the IP
computer_name = Environ("computername") 'get the computer_name
End If
Windows("user_log.xlsx").Activate
Cells(j, 1) = computer_name
Cells(j, 2) = Now()
Cells(j, 3) = ip_1
Cells(j, 4) = Application.UserName
Windows("user_log.xlsx").Visible = True
Workbooks("user_log.xlsx").Close savechanges:=True
Application.ScreenUpdating = True
End Sub
3.即可完成日志log表的自动记入。把这段代码假如到需要执行的sub里面,每次执行sub函数时,就会顺带执行本条代码。
在“Excel 选项”对话框中,选择“自定义功能区”。在右侧的列表中,勾选“开发者”选项卡,然后点击“确定”。步骤2:点击“开发者”选项卡下的“Visual Basic”按钮。这将打开
VBA
编辑器。步骤3:在
VBA
编辑器中,点击“插入”>“模块”。步骤6:在Excel中,点击“开发者”选项卡下的“宏”按钮。在打开的“宏”对话框中,选择“GetConnectedWiFi
IP
s”并点击“运行”。步骤1:打开Excel,点击“开发者”选项卡。如果你没有看到“开发者”选项卡,请先启用它。步骤5:关闭
VBA
编辑器。
'自定义对字段串编码的函数
Public Function UrlEncode(ByRef szString As String) As String
Dim szChar As String
Dim szTemp As String
Dim szCode As String
由于本人正在用 VB 制作一个自动发邮件的木马(我很直白吧),虽然木马不是重点, 发邮件也只是附带功能,但确实用到.然后想要知道区分是哪里发来的,就想到顺便加入计算机名及用户名在邮件中.
当然,
代码
越简单越好,也就干脆 顺便也把
IP
带上吧.
加计算机名 和用户名
text1.text=
VBA
.Environ("computername")
text2.text=
VBA
.Environ("username")
既邮件内容
Email.Textbody = Now().
Sub GetMy
IP
()Dim strComputer As StringDim objWMI As ObjectDim col
IP
As ObjectDim
IP
As ObjectDim i As IntegerstrComputer = "."Set objWMI = GetObject("winmgmts://" & strComputer & "/root/cimv2")Set c
Public Sub SaveActionLog(ByVal sActNo As String, ByVal sActtype As String, ByVal sActDesc As String)Dim Database_Cnn As ADODB.ConnectionDim RS As ADODB.RecordsetDim Cmd As ADODB.CommandDim Param As AD...