1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330
|
<%@ Page Language="VB" %>
<%@ Register TagPrefix="wmx" Namespace="Microsoft.Matrix.Framework.Web.UI" Assembly="Microsoft.Matrix.Framework, Version=0.6.0.0, Culture=neutral, PublicKeyToken=6f763c9966660626" %>
<%@ import Namespace="System.Data" %>
<%@ import Namespace="System.Data.SqlClient" %>
<%@ import Namespace="System.Web.Mail" %>
<%@ import Namespace="System.IO" %>
<%@ import Namespace="System.DirectoryServices" %>
<%@ import Namespace="System.Configuration" %>
<%@ import Namespace="System.Net" %>
<%@ import Namespace="System" %>
<%@ import Namespace="System.Net.DNS" %>
<%@ import Namespace="System.ComponentModel" %>
<%@ import Namespace="System.Management" %>
<%@ import Namespace="System.Runtime.InteropServices" %>
<%@ import Namespace="System" %>
<%@ import Namespace="ActiveDs" %>
<%@ import Namespace="System.Text" %>
<%@ import Namespace="System.Net.NetworkInformation" %>
<%@ import Namespace="System.Net.Sockets" %>
<script runat="server">
' Insert page code here
'
Sub Page_Load()
Dim Ldap As DirectoryEntry = New DirectoryEntry("LDAP://scoot.local", "toto", "toto")
Dim searcher As DirectorySearcher = New DirectorySearcher(Ldap)
searcher.Filter = "(objectClass=computer)"
Dim DirEntry As DirectoryEntry
Dim nom As String
Dim OsVersion As String
Dim Os As String
Dim ServicePack As String
Dim Ip As String
Dim largeInteger As Object
Dim lastLoggedOnDate As Date
Dim reboot As Date
Dim rebootTime As Object
SqlDataSourceControl2.ConnectionString="server='(local)'; trusted_connection=true; database='pspintranet'"
SqlDataSourceControl2.SelectCommand="Select * from Servers"
call SQLExecuteQuery("TRUNCATE TABLE Servers")
'call restart(reboot)
For Each result As SearchResult In searcher.FindAll
DirEntry = result.GetDirectoryEntry
'Response.Write("Nom : " + DirEntry.Properties("Name").value)
'Response.write("Os_version : " + DirEntry.Properties("operatingSystemVersion").value)
'Response.write(" Os : " + DirEntry.Properties("operatingSystem").value)
'Response.write("ServicePack :" + DirEntry.Properties("operatingSystemServicePack").value)
'Response.write("userPrincipalName :" + DirEntry.Properties("userPrincipalName").value)
nom = DirEntry.Properties("Name").value
'insertion des ip dans la DB.
Dim IPHost As IPHostEntry = Dns.Resolve(DirEntry.Properties("Name").value)
Dim addressList As IPAddress() = IPHost.AddressList
Dim b As IPAddress = addressList(0) ' récupère la première adresse
Ip = b.ToString()
OsVersion = DirEntry.Properties("operatingSystemVersion").value
Os = DirEntry.Properties("operatingSystem").value
ServicePack = DirEntry.Properties("operatingSystemServicePack").value
'Test avec WMI
'Dim co As ConnectionOptions = New ConnectionOptions()
'With co
'.Impersonation = System.Management.ImpersonationLevel.Impersonate
'* Use next line for XP
'.Authentication = System.Management.AuthenticationLevel.Packet
'* Use next line for Win prior XP
'.Authentication = System.Management.AuthenticationLevel.Connect
'End With
'co.Username = "toto"
'co.Password = "toto"
'Dim theScope As New ManagementScope("\\ 192.168.1.7 \root\cimv2",co)
'Dim theQuery As New System.Management.ObjectQuery("SELECT * From Win32_OperatingSystem")
'Dim theSearcher As New ManagementObjectSearcher(theScope, theQuery)
'Dim theCollectionOfResults As ManagementObjectCollection = theSearcher.Get()
'For Each currentResult As ManagementObject In theCollectionOfResults
'reboot = currentResult("LastBootUpTime")
'Next
'Try
'Dim time As New ManagementObject("Win32_OperatingSystem")
'time.Get() ' throws ManagementException
'response.write("This shouldn't be displayed.")
'Catch e As ManagementException
'response.Write("ErrorCode :" & e.ErrorCode)
'response.Write("Message :" & e.Message)
'response.Write("Source :" & e.Source)
'If e.ErrorInformation <> Nothing Then 'extended error object
' response.Write("Extended Description : " & e.ErrorInformation("Description"))
'End If
'End Try
'Test avec WMI
'reboot = restart()
call restart(reboot)
'lastLoggedOnDate = ConvertLargeIntToDate(largeInteger)
'largeInteger = DirEntry.Properties("lastLogOn").Value
'lastLoggedOnDate = ConvertLargeIntToDate(largeInteger)
'last_logon = lastLoggedOnDate
'lblError.Text += nom & " - " & OsVersion & " - " & Os & " - " & ServicePack & "<br>"
'Dim IPHost As IPHostEntry = Dns.Resolve(DirEntry.Properties("Name").value)
'Dim addressList As IPAddress() = IPHost.AddressList
'Dim a As IPAddress = addressList(0) ' récupère la première adresse
'lblError.Text += "INSERT INTO Servers (nom,Ip,ServicePack,OsVersion,OsName) VALUES('"& nom &"','" & Ip & "','" & ServicePack &"','" & OsVersion &"', '" & Os &"' )" & "<br>"
call SQLExecuteQuery("INSERT INTO Servers (nom,Ip,Reboot,ServicePack,OsVersion,OsName) VALUES('"& nom &"','" & Ip & "','" & reboot & "','" & ServicePack &"','" & OsVersion &"', '" & Os &"' )")
Next
MxDataGrid1.DataBind()
End Sub
Function SQLExecuteQuery(ByVal sqlQuery As String) As String
Dim a As String
Dim objConnect As New SqlConnection("server='(local)'; trusted_connection=true; database='pspintranet'")
objConnect.Open()
Dim objCommand As New SqlCommand(sqlQuery, objConnect)
a = objCommand.ExecuteNonQuery()
Return a
End Function
Function restart (Byval reboot As Object) As Date
Dim Ip As String
Dim TestConnection As Boolean
Dim Ldap As DirectoryEntry = New DirectoryEntry("LDAP://scoot", "toto", "toto")
Dim searcher As DirectorySearcher = New DirectorySearcher(Ldap)
searcher.Filter = "(objectClass=computer)"
Dim DirEntry As DirectoryEntry
For Each result As SearchResult In searcher.FindAll
DirEntry = result.GetDirectoryEntry
Dim IPHost As IPHostEntry = Dns.Resolve(DirEntry.Properties("Name").value)
Dim addressList As IPAddress() = IPHost.AddressList
Dim b As IPAddress = addressList(0) ' récupère la première adresse
Ip = b.ToString()
Next
Dim co As ConnectionOptions = New ConnectionOptions()
With co
.Impersonation = System.Management.ImpersonationLevel.Impersonate
'* Use next line for XP
.Authentication = System.Management.AuthenticationLevel.Packet
'* Use next line for Win prior XP
'.Authentication = System.Management.AuthenticationLevel.Connect
End With
co.Username = "toto"
co.Password = "toto"
'For Each result As SearchResult In searcher.FindAll
'TestConnection = theScope.IsConnected
' ici je tente de me connecter aux machine de mon réseau
Dim theScope As New ManagementScope("\\ + Ip + \root\cimv2",co)
TestConnection = theScope.IsConnected
if TestConnection = false Then
response.write("Machines :" & Ip)
Else
'For Each currentResult As ManagementObject In theCollectionOfResults
Dim theQuery As New System.Management.ObjectQuery("SELECT * From Win32_OperatingSystem")
Dim theSearcher As New ManagementObjectSearcher(theScope, theQuery)
Dim theCollectionOfResults As ManagementObjectCollection = theSearcher.Get()
For Each currentResult As ManagementObject In theCollectionOfResults
reboot = currentResult ("LastBootUpTime").ToString()
'currentResult("LastBootUpTime").ToString()
return reboot
Next
End if
End Function
'Private Function ConvertLargeIntToDate(ByVal largeInteger As Object) As Date
' Dim typ As Type = largeInteger.GetType()
'Dim highPart As Integer = CInt(typ.InvokeMember("HighPart", Reflection.BindingFlags.GetProperty, Nothing, largeInteger, Nothing))
'Dim lowPart As Integer = CInt(typ.InvokeMember("LowPart", Reflection.BindingFlags.GetProperty, Nothing, largeInteger, Nothing))
'Dim fileTime As Int64 = Convert.ToInt64(highPart * (2 ^ 32))
'Return (DateTime.FromFileTime(fileTime))
'End Function
Sub Button1_Click(sender As Object, e As EventArgs)
'txtPing.Text = Nothing
'pingopts.Ttl = Convert.ToInt32(txtTTL.Text)
Dim ping As Ping = New Ping()
Dim pingreply As PingReply = ping.Send(TextBox1.Text)
response.write("Reply from : " & TextBox1.Text)
Response.Write("<br>")
Response.Write("<br>")
response.write("Time :" & pingreply.RoundtripTime)
Response.Write("<br>")
Response.Write("<br>")
'response.write("TTL :" & Pingreplay.Ttl.ToString())
'Response.Write("<br>")
'Response.Write("<br>")
response.write("Buffer Size :" & pingreply.Buffer.Length.ToString())
Response.Write("<br>")
Response.Write("<br>")
End Sub
Sub Button2_Click(sender As Object, e As EventArgs)
Dim Sql As String
'Sql = "INSERT INTO Servers (nom, Ip, Reboot, ServicePack, OsVersion, OsName, FreeSpace_Go) "
'Sql += "VALUES ( 'TAMAC01', 'Ip', '20020101', 'ServicePack','OsVersion', 'OsName', 200)"
Sql = "UPDATE Servers SET FreeSpace_Go=250 WHERE nom = 'TAMACIT' "
SQLExecuteQueryConnect(Sql, SqlDataSourceControl2.ConnectionString)
End Sub
Function SQLExecuteQueryConnect(ByVal sqlQuery As String, sqlConnect as String) As String
Dim a As String
' CREER LA CONNEXION
Dim objConnect As New SqlConnection(sqlConnect)
objConnect.Open()
' CREER LA COMMANDE
Dim objCommand As New SqlCommand(sqlQuery, objConnect)
' EXECUTER LA COMMANDE
a = objCommand.ExecuteNonQuery()
Return a
End Function
</script>
<html>
<head>
</head>
<body>
<form runat="server">
<p>
<wmx:SqlDataSourceControl id="SqlDataSourceControl2" runat="server" DeleteCommand="" UpdateCommand=""></wmx:SqlDataSourceControl>
<wmx:MxDataGrid id="MxDataGrid1" runat="server" AllowPaging="False" AllowSorting="True" CellPadding="3" DataKeyField="nom_id" DataSourceControlID="SqlDataSourceControl2" DataMember="Servers" BackColor="White" BorderColor="#CCCCCC" BorderWidth="1px" BorderStyle="None">
<FooterStyle backcolor="White" forecolor="#000066"></FooterStyle>
<HeaderStyle backcolor="#006699" font-bold="True" forecolor="White"></HeaderStyle>
<ItemStyle forecolor="#000066"></ItemStyle>
<PagerStyle mode="NumericPages" horizontalalign="Center" backcolor="White" forecolor="#000066"></PagerStyle>
<SelectedItemStyle backcolor="#669999" font-bold="True" forecolor="White"></SelectedItemStyle>
</wmx:MxDataGrid>
<asp:Label id="lblError" runat="server"></asp:Label>
</p>
<p>
</p>
<p>
</p>
<p>
</p>
<p>
<asp:TextBox id="TextBox1" runat="server"></asp:TextBox>
</p>
<p>
<asp:Button id="Button1" onclick="Button1_Click" runat="server" Text="Ping"></asp:Button>
<asp:Button id="Button2" onclick="Button2_Click" runat="server" Text="Udate"></asp:Button>
</p>
<p>
</p>
</form>
</body>
</html> |
Partager