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 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115
|
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>DHCP Manager</title>
<hta:application
ID="DHCP_Manager"
applicationname="DHCP_Manager"
Icon="%SystemRoot%\System32\magnify.exe"
BORDERSTYLE="normal"
INNERBORDER="yes"
NAVIGABLE="yes"
SELECTION="yes"
SHOWINTASKBAR="yes"
scroll="auto"
WINDOWSTATE="maximize">
<!-- ======================================= DEBUT CSS ======================================= -->
<style type="text/css">
body{font-size: 12px;font-family: arial;color:#000000; background-color:#306EFF;}
h1 {text-align : center; font-size : 14px; font-weight : bold;}
#title{background: #56A5EC;border-top: 1px solid #444444;border-bottom: 1px solid #444444;border-right: 1px solid #444444;border-left: 1px solid #444444;font: bold 14px Verdana, sans-serif;}
#infoframe{border: 1px dashed black;color: black;font-weight: bold;padding: 5px 5px 5px 5px;background-color:#82CAFA;}
#warningframe{border: 1px dashed black;color: black;font-weight: bold;padding: 5px 5px 5px 5px;background-color:#FF0000;}
#okframe{border: 1px dashed black;color: black;font-weight: bold;padding: 5px 5px 5px 5px;background-color:#00CC33;}
h4 {text-align : right; font-size : 11px;font-weight : bold;}
table {width:100%;font: 12px;}
table, th{border:1px solid #222222;border:1px solid #444444;border-collapse: collapse;}
caption{color:white; background-color:#555555;font-weight : bold;}
th{background-color:#56A5EC;}
td {border:1px solid #222222;border:1px solid #444444;border-collapse: collapse;background-color:#82CAFA;}
td, th {white-space: nowrap;}
.graph {width:104px;height:10px;padding:1px;border:1px solid white;background:#2C3539;}
.legend {width:30px;height:10px;padding:1px;border:1px solid black;}
.bar {width:0px;height:10px;text-align : right;}
/*
.PB {width:700px;height:10px;padding:1px;border:1px solid white;background:#000000}
.button {padding:1px;border:1px solid #000000;background: #82CAFA;width:130px;margin:auto;}
.more {padding:0px;border:1px solid #000000;background: #6666FF;margin:auto;}
*/
</style>
<!-- ======================================= FIN CSS ======================================= -->
</head>
<!-- ======================================= DEBUT VBS ======================================= -->
<script language="VBScript">
'********************************************************************************
' LOAD
'********************************************************************************
Sub window_Onload
GetCurrentUsername()
FilterSelection.ServerName.Focus
Actions.InnerHTML = "<div id=infoframe>Use with Care. </br> </br>" _
& "The loading time at the first exectution of the script may be long (~1 min 30), so please wait. </br> </br>" _
& "Type the Ip address of the DHCP server you want to manage. </br> </br>" _
& "For best performances run the script locally.</div>"
End sub
'********************************************************************************
'********************************************************************************
' GET CURRENT USER
'********************************************************************************
Function getCurrentUsername()
Set WshNetwork = CreateObject("WScript.Network")
GetCurrentUsername = WshNetwork.UserDomain & "\" & WshNetwork.UserName
UserName.InnerHTML = "Current Username : " & GetCurrentUsername
End Function
'********************************************************************************
'################################################################################
' VIEW SCOPES
'################################################################################
Sub View_Scopes()
ScopesList.InnerHTML = ""
Actions.InnerHTML = ""
DaysOld = 20
MinutesOld = 200
' Affichage d'un statut et récupération des valeurs fournies par l'utilisateur
strDHCPServer = FilterSelection.ServerName.Value
strFilter = FilterSelection.Filter.Value
' Variables
Set objShell = CreateObject("WScript.Shell")
Set fso = CreateObject("Scripting.FileSystemObject")
If len(strDHCPServer) <= 0 Then
Actions.InnerHTML = "<div id=warningframe>Type server name !</div>"
FilterSelection.ServerName.Focus
Exit Sub
Else
Call Verif_IPV4(strDHCPServer,ValidIP)
If ValidIP = False Then
Actions.InnerHTML = "<div id=warningframe>Type a valid IP Address !</div>"
FilterSelection.ServerName.Focus
Exit Sub
End If
End If
' Dump Files Path
DHCP_Dump_File = objShell.ExpandEnvironmentStrings("%temp%") & "\dhcp_dump_" & strDHCPServer & ".txt"
DHCP_Mibs_File = objShell.ExpandEnvironmentStrings("%temp%") & "\dhcp_mibs_" & strDHCPServer & ".txt"
Local_DHCP_Dump_File = objShell.ExpandEnvironmentStrings("%temp%") & "\dhcp_dump_" & strDHCPServer & ".txt"
Remote_DHCP_Dump_File = objShell.ExpandEnvironmentStrings("%SystemDrive%") & "\dhcp_dump_" & strDHCPServer & ".txt"
' Netsh Commands
DHCPDumpCmd = "netsh dhcp server \\" & strDHCPServer & " dump"
DHCPMibsCmd = "netsh dhcp server \\" & strDHCPServer & " show all"
If not (fso.FileExists(DHCP_Mibs_File)) Then
Call NetshCommand(DHCPMibsCmd,DHCP_Mibs_File,strDHCPServer,ResFile1,ResFile2,MibsStatus)
'If ResFile1 = True AND ResFile2 = True Then
If (fso.FileExists(DHCP_Mibs_File)) AND (fso.FileExists(DHCP_Dump_File)) Then
Call Traitement_Scopes(DHCP_Dump_File,DHCP_Mibs_File)
End If
End If
If MibsStatus = True Then Exit Sub
If not (fso.FileExists(DHCP_Dump_File)) Then
'Call NetshCommand(DHCPDumpCmd,DHCP_Dump_File,strDHCPServer,ResFile1,ResFile2)
Call LaunchProcess(strDHCPServer,Remote_DHCP_Dump_File,Local_DHCP_Dump_File)
'If ResFile1 = True AND ResFile2 = True Then
If (fso.FileExists(DHCP_Dump_File)) AND (fso.FileExists(DHCP_Mibs_File)) Then
Call Traitement_Scopes(DHCP_Dump_File,DHCP_Mibs_File)
End If
End If
If (fso.FileExists(DHCP_Dump_File)) AND (fso.FileExists(DHCP_Mibs_File)) Then
set FDump = fso.GetFile(DHCP_Dump_File)
set FMibs = fso.GetFile(DHCP_Mibs_File)
If DateDiff("d", FMibs.DateLastModified, Now()) >= MinutesOld Then
fso.DeleteFile(DHCP_Mibs_File)
Call NetshCommand(DHCPMibsCmd,DHCP_Mibs_File,strDHCPServer,ResFile1,ResFile2,MibsStatus)
'If ResFile1 = True AND ResFile2 = True Then
If (fso.FileExists(DHCP_Dump_File)) AND (fso.FileExists(DHCP_Mibs_File)) Then
Call Traitement_Scopes(DHCP_Dump_File,DHCP_Mibs_File)
End If
ElseIf DateDiff("d", FDump.DateLastModified, Now()) >= DaysOld Then
fso.DeleteFile(DHCP_Dump_File)
'Call NetshCommand(DHCPDumpCmd,DHCP_Dump_File,strDHCPServer,ResFile1,ResFile2)
Call LaunchProcess(strDHCPServer,Remote_DHCP_Dump_File,Local_DHCP_Dump_File)
'If ResFile1 = True AND ResFile2 = True Then
If (fso.FileExists(DHCP_Dump_File)) AND (fso.FileExists(DHCP_Mibs_File)) Then
Call Traitement_Scopes(DHCP_Dump_File,DHCP_Mibs_File)
End If
End If
'If ResFile1 = True AND ResFile2 = True Then
If (fso.FileExists(DHCP_Dump_File)) AND (fso.FileExists(DHCP_Mibs_File)) Then
Call Traitement_Scopes(DHCP_Dump_File,DHCP_Mibs_File)
End If
End If
End Sub
'################################################################################
'********************************************************************************
' GET VALID IPV4
'********************************************************************************
Function Verif_IPV4(IP,ValidIP)
ValidIP = False
Set RegExIP = New RegExp
With RegExIP
.Pattern = "(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})"
.IgnoreCase = True
.Global = False
End With
Set ResultRegExIP = RegExIP.Execute(IP)
If ResultRegExIP.count > 0 Then
ValidIP = True
Exit Function
End If
End Function
'********************************************************************************
'********************************************************************************
' NETSH COMMAND
'********************************************************************************
Function NetshCommand(Command,File,DHCPServer,Result1,Result2,MibsHS)
Result1 = False
Result2 = False
MibsHS = False
Ftype = ""
Dim objConsole
Dim objFSO, objLog
set objConsole = new CliWrapper
Const ForWriting = 2
Const TristateFalse = 0
Const CreateIfNecessary = True
Set objFSO = CreateObject("Scripting.FileSystemObject")
Actions.InnerHTML = "<div id=infoframe>Dumping " & DHCPServer & " configuration in progress, please wait (~1 min 30) ...</div>"
strConsoleOut= objConsole.exec(Command)
AllLigne = strConsoleOut
'Debug
'msgbox AllLigne
If Instr(File,"mibs") > 0 Then
Ftype = "mibs"
End If
If Instr(File,"dump") > 0 Then
Ftype = "dump"
End If
Select Case Ftype
Case "mibs"
If InStr(AllLigne,"Le serveur ne fonctionne ") > 0 Then
Actions.InnerHTML = "<div id=warningframe>Unable to connect to this server or Netsh component is unavailable. </br> </br> Have you registered netsh component with this command : cmd /c NETSH ADD HELPER DHCPMON.DLL ?</div>"
MibsHS = True
Exit Function
End If
If InStr(AllLigne,"La commande suivante n'a pas ") > 0 Then
Actions.InnerHTML = "<div id=warningframe>Unable to connect to this server or Netsh component is unavailable. </br> </br> Have you registered netsh component with this command : cmd /c NETSH ADD HELPER DHCPMON.DLL ?</div>"
MibsHS = True
Exit Function
End If
If InStr(AllLigne,"chec de la commande") > 0 Then
Actions.InnerHTML = "<div id=warningframe>Access denied. </br> </br> Please execute the script with an authorized account.</div>"
MibsHS = True
Exit Function
End If
Result2 = True
Set objLog = objFSO.OpenTextFile(File, ForWriting, CreateIfNecessary, TristateFalse)
objLog.writeline AllLigne
Case "dump"
If Not InStr(AllLigne,"add scope ") > 0 Then
Actions.InnerHTML = "<div id=warningframe>Access denied. </br> </br> Please execute the script with an authorized account.</div>"
Exit Function
End If
Result1 = True
Set objLog = objFSO.OpenTextFile(File, ForWriting, CreateIfNecessary, TristateFalse)
objLog.writeline AllLigne
End Select
End Function
'********************************************************************************
'********************************************************************************
' LAUCH DUMP PROCESS
'********************************************************************************
Function LaunchProcess(DHCPServer,RFile,Lfile)
On Error Resume Next
Set objWMIService = GetObject("winmgmts:"& "{impersonationLevel=impersonate}!\\" & DHCPServer & "\root\cimv2")
Select Case Err.Number
Case 0
Const FEN = 0
Actions.InnerHTML = "<div id=infoframe>Dumping " & DHCPServer & " configuration in progress, please wait (~1 min 30) ...</div>"
strCommand = "cmd /c netsh dhcp server " & DHCPServer & " dump > " & RFile
Set objStartup = objWMIService.Get("Win32_ProcessStartup")
Set objConfig = objStartup.SpawnInstance_
objConfig.ShowWindow = FEN
Set objProcess = objWMIService.Get("Win32_Process")
intReturn = objProcess.Create(strCommand, Null, objConfig, intProcessID)
'wscript.echo intReturn
'wscript.echo intProcessID
ProcessRunning = TRUE
Do Until Not ProcessRunning
'Set colProcessList = objWMIService.ExecQuery ("Select * from Win32_Process Where Name = 'netsh.exe'")
Set colProcessList = objWMIService.ExecQuery ("Select * from Win32_Process Where ProcessId = '" & intProcessID & "'")
If colProcessList.Count = 0 then
ProcessRunning = False
End If
Loop
If intReturn = 0 and ProcessRunning = False Then
Set objShell = CreateObject("WScript.Shell")
strPath = objShell.ExpandEnvironmentStrings("%SystemDrive%")
RFile = Replace(RFile,":","$")
strPath = Replace(strPath,":","$")
strPath = "\\" & DHCPServer & "\" & strPath
'Net use Windows
strCommandMap = "cmd /c net use " & strPath
ReturnCodeMap = objShell.Run(strCommandMap, 0, True)
'Copy
RFile = Replace(RFile,"C$\","")
strCommandCopy = "cmd /c copy " & strPath & "\" & RFile & " " & LFile & " /Y"
ReturnCodeCopy = objShell.Run(strCommandCopy, 0, True)
'Net use Windows
strCommandUNMap = "cmd /c net use " & strPath & " /d /Y"
ReturnCodeUNMap = objShell.Run(strCommandUNMap, 0, True)
End IF
Case 70
' Run-time error '70': Permission denied
Actions.InnerHTML = "<div id=warningframe>Access denied. </br> </br> Please execute the script with an authorized account.</div>"
Case 462
' The remote server machine does not exist or is unavailable
Actions.InnerHTML = "<div id=warningframe>Access denied. </br> </br> Please execute the script with an authorized account.</div>"
Case -2147217375
' Unknown/undocumented runtime error (till this time)
Actions.InnerHTML = "<div id=warningframe>Access denied. </br> </br> Please execute the script with an authorized account.</div>"
Case Else
' Unhandled Run-time error (till this time)
Actions.InnerHTML = "<div id=warningframe>Access denied. </br> </br> Please execute the script with an authorized account.</div>"
End Select
Err.Clear
On Error GoTo 0
End Function
'********************************************************************************
'********************************************************************************
' Déclaration de la classe CliWrapper, qui permet d'exécuter une commande externe sans pop up
'********************************************************************************
Class CliWrapper
public stdout, stderr, command
private sh, fso, syncmode, outfile, errfile
private ForReading, TristateUseDefault, DoNotCreateFile
public function Exec(sCmd)
' clean out old stdout and stderr
stdout = vbNullString: stderr = vbNullString
command = sh.ExpandEnvironmentStrings(sCmd)
sh.Run "%COMSPEC% /c " & sCmd & " 2>" & errfile _
& " 1>" & outfile, 0, syncmode
stderr = ProcessFile(errfile)
stdout = ProcessFile(outfile)
Exec = stdout
end function
private sub class_initialize
' for speed of use over time
Set sh = createobject("WScript.Shell")
Set fso = createobject("Scripting.FileSystemObject")
ForReading = 1: TristateUseDefault = -2
DoNotCreateFile = false
outfile = sh.ExpandEnvironmentStrings("%temp%") & "\" & fso.GetTempName
errfile = sh.ExpandEnvironmentStrings("%temp%") & "\" & fso.GetTempName
syncmode = true
end sub
private function ProcessFile(filepath)
' given the path to a file, will return entire contents
if fso.FileExists(filepath) then
with fso.OpenTextFile(filepath, ForReading, _
false, TristateUseDefault)
if .AtEndOfStream <> true then
ProcessFile = .ReadAll
end if
.Close
fso.DeleteFile(filepath)
end with
else
'msgbox "Erreur avec les fichiers temporaires...",vbExclamation,"Erreur !"
end if
end function
end class
'********************************************************************************
'********************************************************************************
' TRAITEMENT SCOPES
'********************************************************************************
Sub Traitement_Scopes(DHCP_Dump_File,DHCP_Mibs_File)
StartTime = Timer()
strFilter = FilterSelection.Filter.Value
strDHCPServer = FilterSelection.ServerName.Value
Const ForReading = 1
Const ForWriting = 2
Const ModeAscii = 0
Dim objFSO, objFile
Set objFSO = CreateObject("Scripting.FileSystemObject")
' Dictionaries
Set DicoAddValidScope = CreateObject("Scripting.Dictionary")
Set DicoAddScopeStatus = CreateObject("Scripting.Dictionary")
Set DicoAddScopeLease = CreateObject("Scripting.Dictionary")
Set DicoAddMibs = CreateObject("Scripting.Dictionary")
Set DicoAddExcludeRange = CreateObject("Scripting.Dictionary")
DicoAddValidScope.CompareMode = vbTextCompare
DicoAddScopeStatus.CompareMode = vbTextCompare
DicoAddScopeLease.CompareMode = vbTextCompare
DicoAddMibs.CompareMode = vbTextCompare
DicoAddExcludeRange.CompareMode = vbTextCompare
'Read File 1
AllLigne = ""
Ligne = ""
Set Fichier_Parcourir1 = objFSO.OpenTextFile(DHCP_Dump_File,ForReading)
Do While Fichier_Parcourir1.AtEndOfStream <> True
AllLigne = Fichier_Parcourir1.ReadAll
'Debug
'Actions.InnerHTML = AllLigne
Tableau = Split(AllLigne,vbnewline)
For i = lbound(Tableau) to ubound(Tableau)
Ligne = Tableau(i)
' Find Scope and and to dico
If InStr(Ligne,"add scope ") > 0 Then
Call GetScopeInfos(Ligne,mScope,SMask,SName,Sdesc)
Infos = mScope & "#" & SMask & "#" & SName & "#" & Sdesc
If Not DicoAddValidScope.Exists(mScope) Then
DicoAddValidScope.add mScope, Infos
End If
End If
' Find Scope State and and to dico
If InStr(Ligne,"set state ") > 0 Then
Call GetScopeState(Ligne,mScope,State)
If Not DicoAddScopeStatus.Exists(mScope) Then
DicoAddScopeStatus.add mScope, State
End If
End If
' Find Lease and and to dico
If InStr(Ligne,"optionvalue 51 DWORD ") > 0 Then
Call GetScopeLease(Ligne,mScope,gLease)
If Not DicoAddScopeLease.Exists(mScope) Then
DicoAddScopeLease.add mScope, gLease
End If
End If
' Find Exclude Scope
If InStr(Ligne,"excluderange ") > 0 Then
Call GetExcludeRange(Ligne,mScope,StartIP,EndIP)
ExCludeRange = "S:" & StartIP & "E:" & EndIP
If Not DicoAddExcludeRange.Exists(mScope) Then
DicoAddExcludeRange.add mScope, ExCludeRange
Else
ExistValue = DicoAddExcludeRange.item(mScope)
If Not Instr(ExistValue,ExCludeRange ) > 0 Then
DicoAddExcludeRange.remove(mScope)
DicoAddExcludeRange.add mScope, ExistValue & "," & ExCludeRange
End If
End If
End If
Next
Loop
'------
'Read File 2
AllLigne = ""
Ligne = ""
Set Fichier_Parcourir2 = objFSO.OpenTextFile(DHCP_Mibs_File,ForReading)
Do While Fichier_Parcourir2.AtEndOfStream <> True
AllLigne = Fichier_Parcourir2.ReadAll
'Debug
'Actions.InnerHTML = AllLigne
If InStr(AllLigne, "Nombre de MIBÿ:") > 0 Then
Language = "FR"
Lang.InnerHtml = "Language : " & Language
Search_Mibs = "Nombre de MIBÿ:"
Search_Scope = "Sous"
lenght = 15
ElseIf InStr(AllLigne, "MIBCounts:") > 0 Then
Language = "EN"
Lang.InnerHtml = "Language : " & Language
Search_Mibs = "MIBCounts:"
Search_Scope = "Subnet = "
lenght = 10
End If
If InStr(AllLigne, Search_Mibs) > 0 Then
Tableau = Split(AllLigne,vbCrLf)
For i = 0 To UBound(Tableau)
Ligne = Tableau(i)
If Instr(Ligne, Search_Scope) > 0 Then
On error resume next
'Determine Scope name
tScope = Right(Tableau(i), Len(Tableau(i)) - lenght)
tScope = Left(tScope, Len(tScope) - 1)
'Determine number of addresses in use
UsedArray = Split(Tableau(i + 1), "=")
tUsed = CLng(Left(UsedArray(1), Len(UsedArray(1)) - 1))
'Determine number of addresses free
FreeArray = Split(Tableau(i + 2), "=")
tFree = CLng(Left(FreeArray(1), Len(FreeArray(1)) - 1))
'Determine percentage of addresses free
tSumTotal = CLng(tFree + tUsed)
If tSumTotal = 0 Then
'Cannot divide by zero
Else
tPercentFree = (tFree / tSumTotal) * 100
tPercentFree = FormatNumber(tPercentFree, 0)
tPercentUsed = (tUsed / tSumTotal) * 100
tPercentUsed = FormatNumber(tPercentUsed, 0)
Datas = tUsed & "#" & tFree & "#" & tSumTotal & "#" & tPercentFree & "#" & tPercentUsed
End If
DicoAddMibs.add tScope, Datas
On error goto 0
End If
Next
End If
Loop
'------
'msgbox DicoAddValidScope.count
'msgbox DicoAddScopeStatus.count
'msgbox DicoAddScopeLease.count
'msgbox DicoAddExcludeRange.count
'----------------------------------------------------------
' Table Header
strScopeListHeader = "<table>" _
& "<caption>Scopes Informations</caption>" _
& "<tr>" _
& "<th>Count</th>" _
& "<th>Infos</th>" _
& "<th>Scope</th>" _
& "<th>Name</th>" _
& "<th>Lease</th>" _
& "<th>% Usage</th>" _
& "</tr>"
'----------------------------------------------------------
'----------------------------------------------------------
' Legend
ScopeListLegend = "<table>" _
& "<caption>Legend</caption>" _
& "<tr>" _
& "<td>" _
& "Disabled Scope : <span class='legend' style='background-color:#C0C0C0'></span>" _
& " Usage >= 80 % : <span class='legend' style='background-color:#FF0000'></span>" _
& " Usage >= 50 % : <span class='legend' style='background-color:#FF9933'></span>" _
& " Usage < 50 % : <span class='legend' style='background-color:#82CAFA'></span>" _
& "</td>" _
& "</tr>" _
& "</table></br>"
'---------------------------------------------------------
'----------------------------------------------------------
' Export Header
strToExportScopesBodyHeader = "Count" & ";" _
& "Scope" & ";" _
& "Mask" & ";" _
& "Name" & ";" _
& "Description" & ";" _
& "CIDR" & ";" _
& "BROADCAST" & ";" _
& "Total Host" & ";" _
& "IP Range" & ";" _
& "Status" & ";" _
& "Lease" & ";" _
& "Used IP" & ";" _
& "Free IP" & ";" _
& "Total" & ";" _
& "% Free" & ";" _
& "%Used" & ";" _
& "Excluded Range" & ";" _
& vbNewLine
'----------------------------------------------------------
CptScope = 0
IndexKeys = DicoAddValidScope.Keys
Dim strTableBody()
Redim strTableBody(DicoAddValidScope.count)
For key=0 To ubound(IndexKeys)
DicoAddValidScopeValue = DicoAddValidScope.item(IndexKeys(key))
DicoAddScopeStatusValue = DicoAddScopeStatus.item(IndexKeys(key))
DicoAddScopeLeaseValue = DicoAddScopeLease.item(IndexKeys(key))
DicoAddMibsValue = DicoAddMibs.item(IndexKeys(key))
DicoAddExcludeRangeValue = DicoAddExcludeRange.item(IndexKeys(key))
Call Filter_Exist(DicoAddValidScopeValue,strFilter,Exist)
If Exist = True Then
CptScope = CptScope + 1
If Len(DicoAddValidScopeValue) > 0 Then
Tab1 = Split(DicoAddValidScopeValue,"#")
tScope = Tab1(0)
tMask = Tab1(1)
tName = Tab1(2)
tDesc = Tab1(3)
Else
Exit Sub
End If
tCIDR = MaskLength(tMask)
tBROADCAST = CalcBroadcastAddress(tScope,tMask)
tTOTAL_HOST = GetNumberOfAvailableHostAddresses(tCIDR)
tIP_RANGE = Range(tScope,tBROADCAST)
tExclude = "-"
tStatus = "-"
tLease = "-"
tMibs = "-"
If DicoAddExcludeRange.Exists(IndexKeys(key)) Then
tExclude = DicoAddExcludeRangeValue
End If
If DicoAddScopeStatus.Exists(IndexKeys(key)) Then
tStatus = DicoAddScopeStatusValue
HorizontalBar = ""
Select Case tStatus
Case 0
Color = "#C0C0C0" 'Grey
'tUsed = ""
'tFree = ""
'tSumTotal = ""
'tPercentFree = ""
'tPercentUsed = ""
tStatus = "Disabled"
If Len(DicoAddMibsValue) > 0 Then
Tab2 = Split(DicoAddMibsValue,"#")
tUsed = Tab2(0)
tFree = Tab2(1)
tSumTotal = Tab2(2)
tPercentFree = Tab2(3)
tPercentUsed = Tab2(4) & " %"
End If
HorizontalBar = "<div class=" & Chr(34) & "graph" & Chr(34) & "><div class=" & Chr(34) & "bar" & Chr(34) & "style=" & Chr(34) & "background-color:"& color & "; width:" & tPercentUsed & chr(34) & ">" & tPercentUsed &"</div></div>"
Case 1
If Len(DicoAddMibsValue) > 0 Then
Tab2 = Split(DicoAddMibsValue,"#")
tUsed = Tab2(0)
tFree = Tab2(1)
tSumTotal = Tab2(2)
tPercentFree = Tab2(3)
tPercentUsed = Tab2(4)
End If
tStatus = "Enabled"
If tPercentUsed >= 80 Then
Color = "#FF0000" 'Red
tPercentUsed = tPercentUsed & " %"
ElseIf tPercentUsed >= 50 Then
color = "#FF9933" 'Orange
tPercentUsed = tPercentUsed & " %"
Else
Color = "#82CAFA" 'Blue
tPercentUsed = tPercentUsed & " %"
End If
HorizontalBar = "<div class=" & Chr(34) & "graph" & Chr(34) & "><div class=" & Chr(34) & "bar" & Chr(34) & "style=" & Chr(34) & "background-color:"& color & "; width:" & tPercentUsed & chr(34) & ">" & tPercentUsed &"</div></div>"
End Select
End If
If DicoAddScopeLease.Exists(IndexKeys(key)) Then
tLease = DicoAddScopeLeaseValue
End If
If DicoAddMibs.Exists(IndexKeys(key)) Then
tMibs = DicoAddMibsValue
End If
'& "<td style=" & chr(34) & "background-color:" & Color & "" & chr(34) & ">" & tDesc & "</td>" _
'& "<td style=" & chr(34) & "background-color:" & Color & "" & chr(34) & ">" & tPercentUsed & "</td>" _
'& "<td style=" & chr(34) & "background-color:" & Color & "" & chr(34) & ">" & tMask & "</td>" _
'& "<td style=" & chr(34) & "background-color:" & Color & "" & chr(34) & ">" & tBROADCAST & "</td>" _
'& "<td style=" & chr(34) & "background-color:" & Color & "" & chr(34) & ">" & tIP_RANGE & "</td>" _
'& "<td style=" & chr(34) & "background-color:" & Color & "" & chr(34) & ">" & tStatus & "</td>" _
'& "<td style=" & chr(34) & "background-color:" & Color & "" & chr(34) & ">" & tPercentFree & "</td>" _
'& "<td style=" & chr(34) & "background-color:" & Color & "" & chr(34) & ">" & tExclude & "</td>" _
'& "<td style=" & chr(34) & "background-color:" & Color & "" & chr(34) & ">" & tUsed & "</td>" _
'& "<td style=" & chr(34) & "background-color:" & Color & "" & chr(34) & ">" & tSumTotal & "</td>" _
'& "<td style=" & chr(34) & "background-color:" & Color & "" & chr(34) & ">" & tTOTAL_HOST & "</td>" _
'& "<td style=" & chr(34) & "background-color:" & Color & "" & chr(34) & ">/" & tCIDR & "</td>" _
'& "<td style=" & chr(34) & "background-color:" & Color & "" & chr(34) & ">" & tFree & "</td>" _
'& "<td style=" & chr(34) & "background-color:" & Color & "" & chr(34) & ">" & tTOTAL_HOST & "</td>" _
' Table Body
aHTML = "<tr><Form method='POST'>" _
& "<td style=" & chr(34) & "background-color:" & Color & "" & chr(34) & ">" & CptScope & "</td>" _
& "<td style=" & chr(34) & "background-color:" & Color & "" & chr(34) & "><input type='button' Value='Infos' onclick='Call Scope_Infos(tscope.value,tmask.value,tname.value,tdesc.value,tstatus.value,tlease.value,tcidr.value,tbroadcast.value,ttotal_host.value,tip_range.value,tused.value,tfree.value,tsumtotal.value,tpercentfree.value,tpercentused.value,texclude.value)' class='more'></td>" _
& "<td style=" & chr(34) & "background-color:" & Color & "" & chr(34) & ">" & tScope & "</td>" _
& "<input type='hidden' name='tscope' value='" & tScope & "'>" _
& "<input type='hidden' name='tmask' value='" & tMask & "'>" _
& "<td style=" & chr(34) & "background-color:" & Color & "" & chr(34) & ">" & tName & "</td>" _
& "<input type='hidden' name='tname' value='" & tName & "'>" _
& "<input type='hidden' name='tdesc' value='" & tDesc & "'>" _
& "<input type='hidden' name='tcidr' value='" & tCIDR & "'>" _
& "<input type='hidden' name='tbroadcast' value='" & tBROADCAST & "'>" _
& "<input type='hidden' name='ttotal_host' value='" & tTOTAL_HOST & "'>" _
& "<input type='hidden' name='tip_range' value='" & tIP_RANGE & "'>" _
& "<input type='hidden' name='tstatus' value='" & tStatus & "'>" _
& "<td style=" & chr(34) & "background-color:" & Color & "" & chr(34) & ">" & tLease & "</td>" _
& "<input type='hidden' name='tlease' value='" & tLease & "'>" _
& "<input type='hidden' name='tused' value='" & tUsed & "'>" _
& "<input type='hidden' name='tfree' value='" & tFree & "'>" _
& "<input type='hidden' name='tsumtotal' value='" & tSumTotal & "'>" _
& "<input type='hidden' name='tpercentfree' value='" & tPercentFree & "'>" _
& "<td style=" & chr(34) & "background-color:" & Color & "" & chr(34) & ">" & HorizontalBar & "</td>" _
& "<input type='hidden' name='tpercentused' value='" & tPercentUsed & "'>" _
& "<input type='hidden' name='texclude' value='" & tExclude & "'>" _
& "</tr></Form>"
strTableBody(key) = aHTML
strToExportScopesBody = strToExportScopesBody _
& CptScope & ";" _
& tScope & ";" _
& tMask & ";" _
& tName & ";" _
& tDesc & ";" _
& tCIDR & ";" _
& tBROADCAST & ";" _
& tTOTAL_HOST & ";" _
& tIP_RANGE & ";" _
& tStatus & ";" _
& tLease & ";" _
& tUsed & ";" _
& tFree & ";" _
& tSumTotal & ";" _
& tPercentFree & ";" _
& tPercentUsed & ";" _
& tExclude & ";" _
& vbNewLine
strToExportScopesBody = Replace(strToExportScopesBody,"'","")
End If
Next
Dim To_Export
Dim Scopes_CSVFile
To_Export = strToExportScopesBodyHeader & strToExportScopesBody
Scopes_CSVFile = Replace(strFilter," ","_") & "_" & Replace(strDHCPServer,".",".") & "_scopes.csv"
ExportButton = "<input type='hidden' name='Scopes_CSVFile' value='" & Scopes_CSVFile & "'>" _
& "<input type='hidden' name='To_Export' value='" & To_Export & "'>" _
& "<input type='button' value='Export to CSV' onclick='Call ExportToCSV(Scopes_CSVFile.value,To_Export.value)'></br></br>"
strHTML = caca & ScopeListLegend & ExportButton & strScopeListHeader & Join(strTableBody,"") & "</table>"
' Result
If CptScope >= 1 Then
Actions.InnerHTML = "<div id=infoframe>Result with filter : <b>" & strFilter & "</b></br>Execution Time : <b>" & FormatNumber(Timer() - StartTime, 2) & " seconds </b></div>"
ScopesList.InnerHTML = strHTML
FilterSelection.Filter.Focus
Exit Sub
Else
If Len(strFilter) > 0 Then
Actions.InnerHTML = "<div id=warningframe>" & strFilter & " Not Found !</div>"
Else
Actions.InnerHTML = "<div id=warningframe>No data !</div>"
End If
FilterSelection.Filter.Focus
Exit Sub
End If
End Sub
'********************************************************************************
'********************************************************************************
' GET SCOPE INFOS
'********************************************************************************
Function GetScopeInfos(FstrScopeLine,FScope,FMask,FName,FDesc)
If len(FstrScopeLine) > 0 Then
Tab1 = Split(FstrScopeLine," ")
FScope = Tab1(5)
FMask = Tab1(6)
Tab1 = Split(FstrScopeLine,"""")
FName = Tab1(1)
FDesc = Tab1(3)
Else
Exit Function
End If
End Function
'********************************************************************************
'********************************************************************************
' GET SCOPE STATE
'********************************************************************************
Function GetScopeState(strScopeLine,Scope,State)
If len(strScopeLine) > 0 Then
Tab1 = Split(strScopeLine," ")
Scope = Tab1(4)
State = Tab1(7)
Else
Exit Function
End If
End Function
'********************************************************************************
'********************************************************************************
' GET SCOPE LEASE
'********************************************************************************
Function GetScopeLease(strScopeLine,Scope,gLease)
If len(strScopeLine) > 0 Then
on error resume next 'a regarder
Tab1 = Split(strScopeLine," ")
Scope = Tab1(4)
gLease = Tab1(9)
gLease = Replace(gLease,"""","")
If Len(gLease) > 0 Then
If gLease <= 0 Then
gLease = "NO LEASE"
Exit Function
Else
LEASE_H = FormatNumber((gLease/3600),1)
LEASE_D = (LEASE_H/24)
If LEASE_D <= 0 Then
LEASE_D = 0
Else
LEASE_D = FormatNumber((LEASE_H/24),0)
End If
gLease = LEASE_H & " (H) " & LEASE_D & " (D) "
End If
End If
On error goto 0
Else
Exit Function
End If
End Function
'********************************************************************************
'********************************************************************************
' GET EXCLUDE RANGE
'********************************************************************************
Function GetExcludeRange(strScopeLine,Scope,StartIP,EndIP)
If len(strScopeLine) > 0 Then
Tab1 = Split(strScopeLine," ")
Scope = Tab1(4)
StartIP = Tab1(7)
EndIP = Tab1(8)
'ExCludeRange = "S:" & StartIP & "E:" & EndIP
Else
Exit Function
End If
End Function
'********************************************************************************
'********************************************************************************
' GET FILTER
'********************************************************************************
Function Filter_Exist(strToFind,strFilter,Exist)
Exist = False
Set RegExFilter = New RegExp
With RegExFilter
.Pattern = strFilter
.IgnoreCase = True
.Global = False
End With
Set ResultRegExFilter = RegExFilter.Execute(strToFind)
If ResultRegExFilter.count > 0 Then
Exist = True
Exit Function
End If
End Function
'********************************************************************************
'********************************************************************************
'EXPORT TO CSV
'********************************************************************************
Function ExportToCSV(strFile,strData)
If len(strData) > 0 Then
Const ForWriting = 2
Const TristateFalse = 0
Const CreateIfNecessary = True
Dim objFSO, objTextFile
Set objFSO = CreateObject("Scripting.FileSystemObject")
curDir = objFSO.GetAbsolutePathName(".")
Set objTextFile = objFSO.OpenTextFile(strFile, ForWriting, CreateIfNecessary, TristateFalse)
objTextFile.Write (strData)
If err.number <> 0 Then
Actions.InnerHTML = "<div id=warningframe>Error ...</div>"
Exit Function
Else
Actions.InnerHTML = "<div id=okframe>File successfully saved in : " & curDir & "\" & strFile & "</div>"
End If
Else
Exit Function
End If
End Function
'********************************************************************************
'==========================================================================
' Fonction Convertir Mask en CIDR
'--------------------------------------------------------------------------
Function MaskLength(MASK_SCOPE)
Dim arrOctets : arrOctets = Split(MASK_SCOPE, ".")
Dim i
For i = 0 to UBound(arrOctets)
Dim intOctet : intOctet = CInt(arrOctets(i))
Dim j, intMaskLength
For j = 0 To 7
If intOctet And (2^(7 -j)) Then
intMaskLength = intMaskLength + 1
End If
Next
Next
MaskLength = intMaskLength
End Function
'==========================================================================
'==========================================================================
' Fonction Calcul Adresse Broadcast
'--------------------------------------------------------------------------
Function CalcBroadcastAddress(SCOPE,MASK_SCOPE)
Dim strBinIP : strBinIP = ConvertIPToBinary(SCOPE)
Dim strBinMask : strBinMask = ConvertIPToBinary(MASK_SCOPE)
' Set each unmasked bit to 1
Dim i, strBinBroadcast
For i = 1 to Len(strBinIP)
Dim strIPBit : strIPBit = Mid(strBinIP, i, 1)
Dim strMaskBit : strMaskBit = Mid(strBinMask, i, 1)
If strIPBit = "1" Or strMaskBit = "0" Then
strBinBroadcast = strBinBroadcast & "1"
ElseIf strIPBit = "." Then
strBinBroadcast = strBinBroadcast & strIPBit
Else
strBinBroadcast = strBinBroadcast & "0"
End If
Next
CalcBroadcastAddress = ConvertBinIPToDecimal(strBinBroadcast)
End Function
'==========================================================================
'==========================================================================
' Fonction Convertir IP en Binaire
'--------------------------------------------------------------------------
Function ConvertIPToBinary(SCOPE)
Dim arrOctets : arrOctets = Split(SCOPE, ".")
Dim i
For i = 0 to UBound(arrOctets)
Dim intOctet : intOctet = CInt(arrOctets(i))
Dim strBinOctet : strBinOctet = ""
Dim j
For j = 0 To 7
If intOctet And (2^(7 - j)) Then
strBinOctet = strBinOctet & "1"
Else
strBinOctet = strBinOctet & "0"
End If
Next
arrOctets(i) = strBinOctet
Next
ConvertIPToBinary = Join(arrOctets, ".")
End Function
'==========================================================================
'==========================================================================
' Fonction Convertir Binaire en Decimal
'--------------------------------------------------------------------------
Function ConvertBinIPToDecimal(strBinIP)
Dim arrOctets : arrOctets = Split(strBinIP, ".")
Dim i
For i = 0 to UBound(arrOctets)
Dim intOctet : intOctet = 0
Dim j
For j = 0 to 7
Dim intBit : intBit = CInt(Mid(arrOctets(i), j + 1, 1))
If intBit = 1 Then
intOctet = intOctet + 2^(7 - j)
End If
Next
arrOctets(i) = CStr(intOctet)
Next
ConvertBinIPToDecimal = Join(arrOctets, ".")
End Function
'==========================================================================
'==========================================================================
' Fonction Calcul Total hotes pour un réseau
'--------------------------------------------------------------------------
Function GetNumberOfAvailableHostAddresses(CIDR)
Dim nHosts, nAvailableBits
nHosts = -1
nAvailableBits = 32 - CIDR
'wscript.echo nAvailableBits
'Number of Addresses Available for Hosts in Subnet = 2(32 - Number of Masked Bits) - 2
nHosts = (2 ^ nAvailableBits) - 2
GetNumberOfAvailableHostAddresses = nHosts
End Function
'==========================================================================
'==========================================================================
' Fonction Get IP Range
'--------------------------------------------------------------------------
Function Range(FScope,FBROADCAST)
If Len(FScope) > 0 Then
IP_START = Split(FScope, ".")
IP_START_RES = IP_START(0) & "." & IP_START(1) & "." & IP_START(2) & "." & IP_START(3)+1
IP_END = Split(FBROADCAST, ".")
IP_END_RES = IP_END(0) & "." & IP_END(1) & "." & IP_END(2) & "." & IP_END(3)-1
Range = (IP_START_RES & " - " & IP_END_RES)
End If
End Function
'==========================================================================
</script>
</head>
<body>
<br><span id = "VBS_DisplayArea"></span>
<div id="title"><h1>DHCP Manager V1.0</h1></div>
<p>
<span>
<form name="FilterSelection" id="FilterSelection">
<table>
<caption>Select DHCP Server to manage</caption>
<tr>
<td>DHCP Server (Ip Address) : </td>
<td><input name="ServerName" value="10.232.69.58"></td>
</tr>
<tr>
<td>Scope Filter (Blank = No Filter) : </td>
<td><input name="Filter" value=""></td>
</tr>
</table>
</form>
</span>
</p>
<p>
<input type="submit" Value="View Scopes" onClick="View_Scopes()" class="button">
</p>
<span id = "Actions"></span>
<p>
<span id = "ScopesList"></span>
</p>
<h4>Copyright Distributed Windows 2013</br>
<span id = "UserName"></span></br>
<span id = "Lang"></span>
</h4>
</body>
</html> |
Partager