批处理之家's Archiver

522235677 发表于 2022-5-22 09:28

[已解决]批处理如何记录Windows远程桌面登录失败时的IP?

[i=s] 本帖最后由 522235677 于 2022-5-26 14:47 编辑 [/i]

需求:有一个服务器,想记录远程桌面登录失败的IP,并保存到一个文本
详述:在事件查看器当中,在事件ID为4625的事件详情中可以查到IP地址,目前来说可以根据事件来创建计划任务,但是当计划任务中不知道如何来确定是哪个事件、不知道怎么获取事件中的IP地址

求大侠指导

flashercs 发表于 2022-5-22 15:34

powershell获取事件IP地址[code]$evt=Get-WinEvent -LogName Security -FilterXPath "Event[System[EventID=4625 and TimeCreated[timediff(@SystemTime)<=600000]]]" -MaxEvents 1 -ErrorAction SilentlyContinue
if($null -ne $evt){
$evt.Properties[3].Value # IP地址可能不是这个序号
}[/code]

522235677 发表于 2022-5-23 14:03

[b]回复 [url=http://www.bathome.net/redirect.php?goto=findpost&pid=255946&ptid=62803]2#[/url] [i]flashercs[/i] [/b]


    感谢大佬帮忙,但是我测试后,发现脚本只显示0

flashercs 发表于 2022-5-24 17:05

[b]回复 [url=http://www.bathome.net/redirect.php?goto=findpost&pid=255973&ptid=62803]3#[/url] [i]522235677[/i] [/b][code]$evt=Get-WinEvent -LogName Security -FilterXPath "Event[System[EventID=4625 and TimeCreated[timediff(@SystemTime)<=600000]]]" -MaxEvents 1 -ErrorAction SilentlyContinue
if($null -ne $evt){
$evt.Properties
}[/code]

522235677 发表于 2022-5-25 21:19

[b]回复 [url=http://www.bathome.net/redirect.php?goto=findpost&pid=256040&ptid=62803]4#[/url] [i]flashercs[/i] [/b]


    非常感谢大佬的帮助,可以看到IP地址了
还要再请教一下,这个怎么只匹配出ip地址,然后执行一下curl,把这个ip提交
curl [url]http://test.com?ip=%ip%[/url]
肯定大佬赐教

flashercs 发表于 2022-5-25 22:31

[b]回复 [url=http://www.bathome.net/redirect.php?goto=findpost&pid=256097&ptid=62803]5#[/url] [i]522235677[/i] [/b][code]$evt=Get-WinEvent -LogName Security -FilterXPath "Event[System[EventID=4625 and TimeCreated[timediff(@SystemTime)<=600000]]]" -MaxEvents 1 -ErrorAction SilentlyContinue
if($null -ne $evt){
$ip=$evt.Properties[19].Value
curl.exe http://test.com?ip=$ip
}[/code]

522235677 发表于 2022-5-26 14:46

[b]回复 [url=http://www.bathome.net/redirect.php?goto=findpost&pid=256099&ptid=62803]6#[/url] [i]flashercs[/i] [/b]


    感谢大佬帮助,运行成功:kiss:

522235677 发表于 2022-5-30 14:20

[b]回复 [url=http://www.bathome.net/redirect.php?goto=findpost&pid=255946&ptid=62803]2#[/url] [i]flashercs[/i] [/b]


    大佬
Event[System[EventID=4624 and TimeCreated[timediff(@SystemTime)<=600000]]]

这个我想再加个判断 EventData[LogonType=10],我尝试了很多次都失败了,望指导~

flashercs 发表于 2022-5-30 15:02

[b]回复 [url=http://www.bathome.net/redirect.php?goto=findpost&pid=256229&ptid=62803]8#[/url] [i]522235677[/i] [/b][code]"Event[System[EventID=4624 and TimeCreated[timediff(@SystemTime)<=600000]] and EventData[Data[@Name='LogonType']=10]]"[/code]

522235677 发表于 2022-5-30 15:07

[b]回复 [url=http://www.bathome.net/redirect.php?goto=findpost&pid=256233&ptid=62803]9#[/url] [i]flashercs[/i] [/b]


    大佬威武,向大佬学习

页: [1]

Powered by Discuz! Archiver 7.2  © 2001-2009 Comsenz Inc.