您好,登錄后才能下訂單哦!
本篇文章給大家分享的是有關java 中怎么訪問windows安全日志,小編覺得挺實用的,因此分享給大家學習,希望大家閱讀完這篇文章后可以有所收獲,話不多說,跟著小編一起來看看吧。
//查詢window日志 public void queryWindowsData(String ip,String user,String space,String password,String domain) { try { //創(chuàng)建session認證連接 JISession dcomSession =JISession.createSession(domain,user,password); dcomSession.useSessionSecurity(true); JIProgId progId = JIProgId.valueOf("WbemScripting.SWbemLocator"); progId.setAutoRegistration(true); JIComServer comServer = new JIComServer(progId, ip, dcomSession); IJIDispatch wbemLocator = (IJIDispatch) JIObjectFactory.narrowObject(comServer.createInstance().queryInterface(IJIDispatch.IID)); //parameterstoconnecttoWbemScripting.SWbemLocator JIVariant[] results = wbemLocator.callMethodA("ConnectServer", new Object[]{ JIVariant.OPTIONAL_PARAM(), (space == null) ? JIVariant.OPTIONAL_PARAM() : new JIString(space) , JIVariant.OPTIONAL_PARAM(), JIVariant.OPTIONAL_PARAM(), JIVariant.OPTIONAL_PARAM() , JIVariant.OPTIONAL_PARAM() , 0 , JIVariant.OPTIONAL_PARAM() }); IJIDispatch wbemServices=(IJIDispatch)JIObjectFactory.narrowObject(results[0].getObjectAsComObject()); //String sql = "SELECT * FROM Win32_ComputerSystem"; SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); Calendar cc=Calendar.getInstance(); //utc時間-8 //eventcode = 4769 表示通過加域登錄的用戶 cc.add(Calendar.HOUR_OF_DAY, -9);//1小時前 ,8是減去UTC時間 String dateString = sdf.format(cc.getTime()); //WQL查詢日志 String QUERY_FOR_ALL_LOG_EVENTS = "Select * from Win32_NTLogEvent Where Logfile = 'Security' and " + "EventCode = '4769' and EventType = 4 and TimeWritten >' "+dateString+"'"; try { results = wbemServices.callMethodA("ExecQuery", new Object[]{new JIString(QUERY_FOR_ALL_LOG_EVENTS), JIVariant.OPTIONAL_PARAM(), JIVariant.OPTIONAL_PARAM(), JIVariant.OPTIONAL_PARAM()}); IJIDispatch wOSd = (IJIDispatch) JIObjectFactory.narrowObject((results[0]).getObjectAsComObject()); int count = wOSd.get("Count").getObjectAsInt(); IJIComObject enumComObject = wOSd.get("_NewEnum").getObjectAsComObject(); IJIEnumVariant enumVariant = (IJIEnumVariant) JIObjectFactory.narrowObject(enumComObject.queryInterface(IJIEnumVariant.IID)); IJIDispatch wbemObject_dispatch = null; for (int c = 0; c < count; c++) { Object[] values = enumVariant.next(1); JIArray array = (JIArray) values[0]; Object[] arrayObj = (Object[]) array.getArrayInstance(); for (int j = 0; j < arrayObj.length; j++) { // (IJIDispatch) JIObjectFactory.narrowObject(((JIVariant) arrayObj[j]). wbemObject_dispatch = (IJIDispatch) JIObjectFactory.narrowObject(((JIVariant) arrayObj[j]).getObjectAsComObject()); } String str = (wbemObject_dispatch.callMethodA("GetObjectText_", new Object[]{1}))[0] .getObjectAsString2(); query(str); } } catch (JIException e) { e.printStackTrace(); } } catch (Exception e) { e.printStackTrace(); } }
以上就是java 中怎么訪問windows安全日志,小編相信有部分知識點可能是我們日常工作會見到或用到的。希望你能通過這篇文章學到更多知識。更多詳情敬請關注億速云行業(yè)資訊頻道。
免責聲明:本站發(fā)布的內容(圖片、視頻和文字)以原創(chuàng)、轉載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權內容。