Saturday, September 10, 2011
FAILED LOGINS
IF NOT (SELECT CAST(LEFT(CAST(Serverproperty('ProductVersion') AS VARCHAR(128)),
Charindex('.', CAST(
Serverproperty('ProductVersion') AS
VARCHAR(128))) - 1) AS INT)) IN ( 8 )
BEGIN
-- NOT SQL 2000 -
DECLARE @SQL_Select AS VARCHAR(4000)
EXEC ('
IF OBJECT_ID(''tempdb..#FailedLogin'') IS NOT NULL
DROP TABLE #FailedLogin
CREATE TABLE #FailedLogin (
EventID INT IDENTITY(1,1) NOT NULL PRIMARY KEY CLUSTERED,
EventDate DATETIME NOT NULL,
LoginName sysname NOT NULL,
ClientName NVARCHAR(255) NULL
)
IF OBJECT_ID(''tempdb..#ErrorLog'') IS NOT NULL
DROP TABLE #ErrorLog
CREATE TABLE #ErrorLog (
LogDate DATETIME,
ProcessInfo NVARCHAR(255),
LogText NVARCHAR(MAX)
)
INSERT INTO #ErrorLog (
[LogDate],
[ProcessInfo],
[LogText]
)
EXEC xp_readerrorlog 0, 1, ''Login Failed''
INSERT INTO #FailedLogin
(EventDate, LoginName, ClientName)
SELECT LogDate
,CASE WHEN CHARINDEX('''''''' , LogText) > 0 THEN SUBSTRING(LogText, CHARINDEX('''''''' , LogText) + 1, CHARINDEX('''''''', LogText, CHARINDEX('''''''' , LogText) + 1) - CHARINDEX('''''''' , LogText) - 1) ELSE ''Login Name Unknown'' END LoginName
,CASE WHEN CHARINDEX(''[CLIENT'', LogText) > 0 THEN SUBSTRING(LogText, CHARINDEX(''[CLIENT'', LogText) + 9, CHARINDEX('']'', LogText) - CHARINDEX(''[CLIENT'', LogText) - 9) ELSE ''IP Address Unknown'' END ClientName
FROM #ErrorLog
WHERE ProcessInfo = ''Logon''
AND CHARINDEX(''Login failed'', LogText) > 0
SELECT MAX(EventDate) as [Last Failure]
,COUNT(EventDate) as [Failed Count]
,LoginName as [Login_Name]
,ClientName as [Client IP]
FROM #FailedLogin
GROUP BY LoginName, ClientName
DROP TABLE #ErrorLog
DROP TABLE #FailedLogin
')
END
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment