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 |
Remove-Variable * -ErrorAction SilentlyContinue; Remove-Module *; $error.Clear(); Clear-Host #This will Break the Webcall scripts #https://stackoverflow.com/questions/47542628/cannot-convert-argument-second-time-in-powershell #https://www.slipstick.com/developer/change-programmatic-access-options/ #$proxy = New-WebServiceProxy -uri "http://localhost:8080/API.asmx?WSDL" -namespace "com.api" -class "MyProxyClass" #$proxy = New-WebServiceProxy -uri "http://localhost:8080/API.asmx?WSDL" -namespace "MyPortal" -class "MyProxyClass" # load the required .NET types Add-Type -AssemblyName 'Microsoft.Office.Interop.Outlook' $GCalenderItems = $null #Makes global Car $End = (Get-Date).AddDays(14).ToShortDateString() $Start = (Get-Date).AddDays(-14).ToShortDateString() Function Get-OutlookCalendar { # access Outlook object model $outlook = New-Object -ComObject outlook.application # connect to the appropriate location $namespace = $outlook.GetNameSpace('MAPI') $Calendar = [Microsoft.Office.Interop.Outlook.OlDefaultFolders]::olFolderCalendar $Filter = "[MessageClass]='IPM.Appointment' and [IsRecurring] = '$False' AND [Start] > '$Start' AND [Start] < '$End'" # AND [End] < '$End'" #AND [Start] > '$Start' AND [End] < '$End'" $CalenderItems = $namespace.getDefaultFolder($Calendar).Items.Restrict($Filter) $CalenderItems | Select-Object -Property Start, Subject write-host "There are $($CalenderItems.Count) calendar entries. Fetching between $($start) and $($end)" #write-host "There are $($CalenderItems.Items.Count) calendar entries. Fetching between $($start) and $($end)" #$folder #$CalenderItems | Select-Object -Property Start, End, Categories, Subject, IsRecurring, Organizer #$folder | gm return $CalenderItems #$dataToReturn = $folder.Items.Restrict($Filter) # | Select-Object -Property Start, End, Categories, Subject, IsRecurring, Organizer $folder.items | Select-Object -Property Start, Categories, Subject, IsRecurring, Organizer $data = $folder.items | Select-Object -Property Start, Categories, Subject, IsRecurring, Organizer $data | Where-Object ($_.Subject -ne "!@#!#!$") $cal = $data | Where-Object ($_Subject -CContains "paceart") write-host "Completed" } $GCalenderItems = Get-OutlookCalendar function add-appointment(){ <# .SYNOPSIS Creates and appointment in outlook .DESCRIPTION Creates an appointment in outlook in the default calendar folder .PARAMETER TimeDate Time and Date of the appointment. Multiple formats are accepted. Please use the one common to your region. It will create the appointment for today if no date is specified. .PARAMETER Location The message to be send. .PARAMETER ReminderMinutesBeforeStart Sets when to send reminder for appointment. Default is 15 minutes. 1440 minutes are in a day and 10080 minutes in a week. Set it to 0 for no reminders. .PARAMETER Subject The subject of the appointment. .EXAMPLE add-appointment -TimeDate "1/4/2015 4:30 pm" -Subject "Little Mermaid" -location "Cameo Theater" -ReminderMinutesBeforeStart 0 This example adds a appointment on 1/4/2015 at 4:30 PM with subject Little mermaid and no reminder. .NOTES Requires Windows PowerShell v2 or later and Microsoft Office Outlook 2010 or later. Outlook cannot be running when running this script.Some versions of Outlook will not close the session. Please go to taskbar and close manually in that case. #> [CmdletBinding()] param ( [parameter(Mandatory=$true,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true)] $TimeDate, [parameter(Mandatory=$true,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true)] $Subject , $location, [int]$ReminderMinutesBeforeStart = "15" ) $AppointmentTime = get-date $Timedate #Check whether Outlook is installed if (-not (Test-Path "HKLM:\Software\Microsoft\Windows\CurrentVersion\App Paths\OUTLOOK.EXE")) { Write-Warning "Outlook is not installed. You need to install Outlook 2010 or later to use this Script." break } #Check if Outlook is running. $OutlookState = Get-Process | Where-Object {$_.Name -eq "outlook"} if ($OutlookState) { Write-Warning "Outlook is running. Please close outlook to run this script" break } $outlook = new-object -com Outlook.Application $calendar = $outlook.Session.GetDefaultFolder(9) # == olFolderCalendar $appt = $calendar.Items.Add(1) # == olAppointmentItem $appt.Start = [datetime]$AppointmentTime $appt.Subject = $subject $appt.Location = $location $appt.ReminderSet = $true $appt.ReminderMinutesBeforeStart =$ReminderMinutesBeforeStart $appt.Save() $outlook.Quit() } if ( !(Test-Path variable:proxy) ) { $proxy = New-WebServiceProxy -uri "https://MyPortal/API.asmx?WSDL" -namespace "MyPortal" -UseDefaultCredential #$proxy = New-WebServiceProxy -uri "http://localhost:8080/API.asmx" -namespace "MyPortal" -UseDefaultCredential } function AdvanceSearch-appointment(){ $Outlook = New-Object -ComObject Outlook.Application Unregister-Event * Register-ObjectEvent -InputObject $Outlook -EventName "AdvancedSearchComplete" -Action { Write-Host "ADVANCED SEARCH COMPLETE" $Args.Scope "Results: " $Args.Results if ($Args.Results) { foreach ($result in $Args.Results) { write-host "==================================================" write-host $result.Subject write-host $result.ReceivedTime write-host $result.SenderName write-host "==================================================" } } } #$olFolders = “Microsoft.Office.Interop.Outlook.OlDefaultFolders” -as [type] $olFolders = [Microsoft.Office.Interop.Outlook.OlDefaultFolders]::olFolderCalendar $NameSpace = $Outlook.GetNameSpace(“MAPI”) #$Scope = $NameSpace.getDefaultFolder($olFolders::olFolderCalendar) #'Inbox' $Scope = 'Inbox' #$NameSpace.getDefaultFolder($olFolders) #'Inbox' #'Calendar' $Emails = $Outlook.AdvancedSearch( $Scope, "", $true ) #urn:schemas:calendar:subject != '%' #$Emails } $person = New-Object "MyPortal.ThePerson"; $person.FirstName = "Frederick"; $person.LastName = "DebYouSee"; $Command = New-Object "MyPortal.SystemChange"; $Command = $proxy.Jira_QueryAllOpenChangeControlsThisWeek(50); $ol = New-Object -ComObject Outlook.Application; $meeting = $ol.CreateItem('olAppointmentItem'); $calendar = $ol.Session.GetDefaultFolder(9) # == olFolderCalendar :nextCalendarItem foreach($file in $Command) { [string]$MyTitle = " CC" + $file.Ticket + ": " + $file.summary; Write-Host $MyTitle; #$file.Ticket.ToString().Trim() ": " $file.summary.ToString().Trim(); #$GCalenderItems | Select-Object -Property Start, Subject foreach ($result in $GCalenderItems) { if ($result.Subject -like $MyTitle) { write-host "==================================================" write-host $result.Start write-host $result.End write-host $result.Subject write-host "==================================================" continue nextCalendarItem; } } Write-Host $file.PlannedStartDate; Write-Host $file.PlannedEndDate; $meeting.Subject = "$MyTitle"; $meeting.Body = $file.description; $meeting.Categories = "ChangeControlReminder"; $meeting.Location = 'Change Control Reminder'; $meeting.ReminderSet = $true; $meeting.Importance = 1; $meeting.MeetingStatus = [Microsoft.Office.Interop.Outlook.OlMeetingStatus]::olMeeting #$meeting.Recipients.Add('mjones@contoso.net') $meeting.ReminderMinutesBeforeStart = 15 $StartDate = [DateTime]::Parse($file.PlannedStartDate, [System.Globalization.CultureInfo]::InvariantCulture); #$file.PlannedStartDate#DateTime.Parse() #System.Globalization.CultureInfo.InvariantCulture $EndDate = [DateTime]::Parse($file.PlannedEndDate, [System.Globalization.CultureInfo]::InvariantCulture); #$file.PlannedStartDate#DateTime.Parse() #System.Globalization.CultureInfo.InvariantCulture $duration = $EndDate - $StartDate $meeting.Start = $StartDate if ($duration.TotalHours -gt 8) { $meeting.Duration = 30 } else { $meeting.Duration = $duration.TotalMinutes } #$meeting.Send() $appt = $calendar.Items.Add(1) # == olAppointmentItem $appt.Start = $StartDate; if ($duration.TotalHours -gt 8) { $appt.Duration = 30 } else { $appt.Duration = $duration.TotalMinutes } $appt.Subject = "$MyTitle"; $appt.Body = $file.description; $appt.Location = $location; $appt.Categories = "ChangeControlReminder"; $appt.Location = 'Change Control Reminder'; $appt | gm $appt.ReminderSet = $false; $appt.Importance = 1; $appt.BusyStatus = [Microsoft.Office.Interop.Outlook.OlBusyStatus]::olFree; $appt.ReminderMinutesBeforeStart = $ReminderMinutesBeforeStart; $appt.Save(); } #Invoke-Expression $Command; #$proxy.Dispose(); #You must dispose of the proxy IN YOUR SCRIPT, powershell will not do it for you! |
Soapcalls from PHP to .NET Web services
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 |
#!/usr/bin/php -q <?php //Creates a check for HTTP and HTTPS services. Also creates a SSL cert check. //Every host is scanned for the ports listed below, and if an web service is found, a service check is created for it. $database_folder = "/etc/nagios/scripts/auto_generate_database/"; //Folder of the SQLLite databases to use for host lookup. $outputfile = "autoconfig_Custom-services.cfg"; #$outputfile = "/etc/nagios/conf.d/auto_generated/autoconfig_http-services.cfg"; $check_http = "/etc/nagios/plugins/check_http"; //Location of Nagios check_http command. This command does all the work and the config is bases on what this command returns. $servicehttps_ports_array = array("443","8443","9443","18200","18201","18202","18203","18204","18205","18206","18207","18208","18209","18210");// array of ports for SSL/TLS checks. Also creates a cert check for each ones of these. $servicehttp_ports_array = array("80","8080","8888");// array of ports for normal HTTP checks $httpcodes = "200,301,302,403,404"; //HTTP codes that are OK //////////////////////////// MAIN //////////////////////////// #var_dump($argv); #exit(); include_once("/etc/nagios/scripts/lib/check_for_custom_config_lib.php"); //Load check for custom config library. $servicegroups_array = array();// Servicegroup array $servicehttp_array = array();// http service array $servicehttps_array = array();// https service array //Open the database with a list of servers. $dbh = new PDO("sqlite:$database_folder/servers.sqlite3") or die("cannot open the database"); //Build the arrays foreach($servicehttps_ports_array as $port) { $servicehttps_array["$port"] = array(); } foreach($servicehttp_ports_array as $port) { $servicehttp_array["$port"] = array(); } $stmt = $dbh->query("SELECT * FROM servers;"); $debug_count = 0; if($argc>1) { echo "Pinging $argv[1] \r\n"; //ping to see if the host is up. exec("ping -c 1 $argv[1]", $null, $result); if (!($result == 0)){ continue;} echo "Checking $argv[1] with ISPortal \r"; $Output = NagiosServiceCheck($argv[1]); echo $Output; $fh= fopen($argv[1],'w'); fwrite($fh, $Output); fclose($fh); } else { //Loop over the list of servers. foreach ($stmt as $row) { $host = $row["hostname"]; $ip = $row["ip"]; echo "Pinging $host \r\n"; //ping to see if the host is up. exec("ping -c 1 $ip", $null, $result); if (!($result == 0)){ continue;} echo "Checking $host with ISPortal \r"; #httpChecks($host,$ip); //Check for HTTP and HTTPS ports $Output = NagiosServiceCheck($host); echo $Output; $fh= fopen($host,'w'); fwrite($fh, $Output); fclose($fh); $debug_count++; # if ($debug_count > 50) {break 1;} //Stop after X servers for testing } } exit(); function ServiceCheck($ServiceName) { switch ($i) { case 0: echo "i equals 0"; break; case 1: echo "i equals 1"; break; case 2: echo "i equals 2"; break; } } function NagiosServiceCheck($host) { try { #$client = new SoapClient("https://IsPortal/API.asmx?WSDL", array('login' => "EID@FQDN.COM", 'password' => "MyPasswordGoesHere", 'user_agent' => 'PHPSoapClient')); $client = new SoapClient("https://IsPortal/API.asmx?WSDL", array('user_agent' => 'PHPSoapClient', 'cache_wsdl' => WSDL_CACHE_NONE)); #var_dump($client->__getFunctions()); #$result = $client->HelloWorld()->HelloWorldResult; #$result = $client->Testing_HelloWorld()->Testing_HelloWorldResult; #$result = $client->Nagios_GenerateCustomServices($host, "true")->Nagios_GenerateCustomServicesResult; #$result = $client->__soapCall(Nagios_GenerateCustomServices, 'Hostname' => '$host', 'MustBeSetToAutomatic', => 'True')->Nagios_GenerateCustomServicesResult; #$result = $client->Nagios_GenerateCustomServices(new SoapParam('Hostname', $Hostname), new SoapParam("True", $MustBeSetToAutomatic))->Nagios_GenerateCustomServicesResult; #$result = $client->Nagios_GenerateCustomServices(array('parameters' => $params))->Nagios_GenerateCustomServicesResult; $params = array('Hostname' => $host, 'MustBeSetToAutomatic' => 'True'); $result = $client->__soapCall('Nagios_GenerateCustomServices', array('parameters' => $params))->Nagios_GenerateCustomServicesResult; #echo $result; return $result; } catch (Exception $e) { echo 'caught execption: ', $e->getMessage(), "\n"; } } function httpChecks($host,$ip) { global $httpcodes,$check_http,$servicehttp_array,$servicehttps_array,$servicehttps_ports_array,$servicehttp_ports_array; //Check for an active HTTP service on an array of ports. foreach($servicehttp_ports_array as $port) { ///Check for an active HTTP service on an array of ports. $output_array = array(); exec ($check_http." -p $port -H $ip --expect=$httpcodes -t 2", $output_array); //Use the Nagios check_http to probe the ports. if( preg_match("/HTTP OK:/",$output_array[0]) ) { echo "HTTP $port found for $host \n"; array_push($servicehttp_array["$port"], $host); //dump found host and port into array //var_dump($servicehttps_array); } } //Check for an active HTTPS service on an array of ports. foreach($servicehttps_ports_array as $port) { $output_array = array(); exec ($check_http." -p $port -H $ip -S --expect=$httpcodes -t 2", $output_array); //Use the Nagios check_http to probe the ports. if( preg_match("/HTTP OK:/",$output_array[0]) ) { echo "HTTPS $port found for $host \n"; array_push($servicehttps_array["$port"], $host); //dump found host and port into array //var_dump($servicehttps_array); } } } function generateServiceGroups($servicegroups_array) { //Create a service group for each new service monitored. $output_group = ""; $servicegroups_array = array_unique($servicegroups_array); foreach($servicegroups_array as $name) { echo "servicegroup:$name\n"; $output_group .= "define servicegroup{\n"; $output_group .= " servicegroup_name $name\n"; $output_group .= " alias\n"; $output_group .= "}\n"; } return($output_group); } function generateServiceHTTP($servicehttp_array,$servicehttp_ports_array){ $service_list = ""; $service = ""; global $servicegroups_array,$httpcodes; //loop over each port. foreach($servicehttp_ports_array as $port) { $service_list = ""; if (count($servicehttp_array[$port]) > 0) { //loop over the array foreach($servicehttp_array[$port] as $host) { //skip if there is a custom config. if (checkForCustomConfig($host,"HTTP $port")) { continue; } //Put additional check here. //Service is good, add it to the list. $service_list .= $host . ","; } $service_list=substr_replace($service_list,"",-1); //remove ending comma $service .="define service{\n"; $service .=" use generic-service\n"; $service .=" host_name $service_list\n"; $service .=" service_description HTTP $port\n"; $service .=" check_command check_web! --expect=$httpcodes -p $port -w 8 -c 9\n"; $service .=" check_interval 5\n"; $service .=" flap_detection_enabled 0\n"; $service .=" retry_interval 1\n"; $service .=" notifications_enabled 0\n"; $service .=" servicegroups http-checks-$port\n"; $service .=" contact_groups OpsSysadmin\n"; $service .=" notes HTTP $port Website checks\n"; $service .="}\n"; array_push($servicegroups_array,"http-checks-$port"); } } return($service); } function generateServiceHTTPS($servicehttps_array,$servicehttps_ports_array){ $service_list = ""; $service = ""; global $servicegroups_array,$httpcodes;; //loop over each port. foreach($servicehttps_ports_array as $port) { $service_list = ""; if (count($servicehttps_array[$port]) > 0) { //loop over the array foreach($servicehttps_array[$port] as $host) { //skip if there is a custom config. if (checkForCustomConfig($host,"HTTPS $port")) { continue; } //Put additional check here. //Service is good, add it to the list. $service_list .= $host . ","; } $service_list=substr_replace($service_list,"",-1); //remove ending comma $service .="define service{\n"; $service .=" use generic-service\n"; $service .=" host_name $service_list\n"; $service .=" service_description HTTPS $port\n"; $service .=" check_command check_web! --expect=$httpcodes -p $port -w 8 -c 9 --ssl\n"; $service .=" check_interval 5\n"; $service .=" flap_detection_enabled 0\n"; $service .=" retry_interval 1\n"; $service .=" notifications_enabled 0\n"; $service .=" servicegroups https-checks-$port\n"; $service .=" contact_groups OpsSysadmin\n"; $service .=" notes HTTPS $port Website checks\n"; $service .="}\n"; array_push($servicegroups_array,"https-checks-$port"); } } return($service); } function generateServiceHTTPSCert($servicehttps_array,$servicehttps_ports_array){ $service_list = ""; $service = ""; global $servicegroups_array,$httpcodes; //loop over each port. foreach($servicehttps_ports_array as $port) { $service_list = ""; if (count($servicehttps_array[$port]) > 0) { //loop over the array foreach($servicehttps_array[$port] as $host) { //skip if there is a custom config. if (checkForCustomConfig($host,"HTTPS $port SSL Cert Expiration")) { continue; } //Put additional check here. //Service is good, add it to the list. $service_list .= $host . ","; } $service_list=substr_replace($service_list,"",-1); //remove ending comma $service .="define service{\n"; $service .=" use generic-service\n"; $service .=" host_name $service_list\n"; $service .=" service_description HTTPS $port SSL Cert Expiration\n"; $service .=" check_command check_web!--expect=$httpcodes -p $port -w 8 -c 9 --ssl -C 20\n"; $service .=" check_interval 5\n"; $service .=" flap_detection_enabled 0\n"; $service .=" retry_interval 1\n"; $service .=" notifications_enabled 0\n"; $service .=" servicegroups https-cert-checks-$port\n"; $service .=" contact_groups OpsSysadmin\n"; $service .=" notes HTTPS $port SSL Cert Expiration checks\n"; $service .="}\n"; array_push($servicegroups_array,"https-cert-checks-$port"); } } return($service); } //------------------------------End of script. Functions below ------------------------- |
VB.NET
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 |
<WebMethod()> Public Function Nagios_GenerateCustomServices(ByVal Hostname As String, ByVal MustBeSetToAutomatic As Boolean) Dim ReturnedArray As ArrayList If MustBeSetToAutomatic Then ReturnedArray = MyModule.DetectServerServices(Hostname, ServiceProcess.ServiceStartMode.Automatic) Else ReturnedArray = MyModule.DetectServerServices(Hostname, -1) End If Dim Host As String = "define host{ use linux-server host_name " & Hostname & " alias " & Hostname & " address " & System.Net.Dns.GetHostByName(Hostname).AddressList(0).ToString & " notes Ex. vBlock - VCE PowerPath hostgroups Ex. vBlock_linux_appliance } " Dim Data As String = Nothing Data = Host If MustBeSetToAutomatic Then For I = 0 To ReturnedArray.Count - 1 If (ReturnedArray(I).ToString.StartsWith("!")) Then Continue For End If Data &= "define service{ use generic-service host_name " & Hostname & " service_description " & ReturnedArray(I).ToString.Replace("\(", "(").Replace("\)", ")") & " check_command CheckServiceSNMP!" & ReturnedArray(I) & " check_interval 60 retry_interval 1 notification_interval 60 contact_groups nicholas event_handler start_service!start_" & ReturnedArray(I) & " max_check_attempts 2 notifications_enabled 1 } " 'root@Hostname[Nagios]:/usr/lib64/nagios/plugins# ./check_SNMP_service_displayname_emc MySnmpCommunity IsPortal "Power" Next Else For I = 0 To ReturnedArray.Count - 1 If Not (ReturnedArray(I).ToString.StartsWith("!")) Then Continue For End If Data &= "define service{ use generic-service host_name " & Hostname & " service_description " & ReturnedArray(I).ToString.Substring(1).Replace("\(", "(").Replace("\)", ")") & " check_command CheckServiceSNMP!" & ReturnedArray(I) & " check_interval 60 retry_interval 1 notification_interval 60 contact_groups TheGrouup event_handler start_service!start_" & ReturnedArray(I) & " max_check_attempts 2 notifications_enabled 1 } " Next End If Return Data End Function |
simple VB Form Web Fuzzer
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 |
Public Class Form1 Dim NewLetter As Char Dim MyWebRequest As New Net.WebClient() Dim Extention As String = ".cfm" Dim FileLen As Integer = 0 Dim SleepTime As Integer = 1000 Const WebSite As String = "http://MyWebsite.com/" Private Sub ExplorePath(ByVal RequestString As String, Optional ByVal LastAscii As Integer = 0) Application.DoEvents() Dim Data As Byte() = Nothing Dim NumberOfFilesFound As Integer = 0 Dim DataLength As Integer = 0 NumberOfFilesFound = 0 Debug.WriteLine("Trying: " & WebSite & RequestString & "<" & Extention) Try If LastAscii = 0 Then Data = MyWebRequest.DownloadData(WebSite & RequestString & "<" & Extention) Else Data = MyWebRequest.DownloadData(WebSite & RequestString & Chr(LastAscii) & "<" & Extention) End If If DataLength <> Data.Length Then If LastAscii = 0 Then ListBox1.Items.Add(RequestString & "<" & Extention) Else ListBox1.Items.Add(RequestString & Chr(LastAscii) & "<" & Extention) Try MyWebRequest.DownloadData(WebSite & RequestString & Chr(LastAscii) & Extention) ListBox1.Items.Add("--[" & RequestString & Chr(LastAscii) & Extention & "]--") Catch ex As Exception End Try ExplorePath(RequestString & ChrW(LastAscii), 48) End If End If Catch ex As Exception DataLength = 0 End Try Select Case LastAscii Case 0 LastAscii = 48 Case 58 LastAscii = 65 'A Case 91 LastAscii = 48 'Zero Return Case Else LastAscii += 1 End Select Threading.Thread.Sleep(SleepTime) ExplorePath(RequestString, LastAscii) End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click 'THIS CAN DOS THE SYSTEM 'Add a Sleep Command 'Exit Sub Dim MyThread(25) As Threading.Thread Dim MyThreadClass(25) As ThreadClassAction If TextBox2.Text = "" Then For i = 0 To 25 MyThreadClass(i) = New ThreadClassAction MyThreadClass(i).CallBack = Me MyThread(i) = New Threading.Thread(AddressOf MyThreadClass(i).Launch) MyThread(i).Name = Chr(Asc("A") + i) MyThread(i).IsBackground = True MyThread(i).Start() Next Else Extention = TextBox1.Text ExplorePath(TextBox2.Text) MsgBox("Done!") End If End Sub End Class Public Class ThreadClass Public CallBack As Form Public Data As String Public Sub AddListItem1() Form1.ListBox1.Items.Add(Data) End Sub Public Sub AddListItem2() Form1.ListBox2.Items.Add(Data) End Sub End Class Public Class ThreadClassAction Public CallBack As Form Dim MyWebRequest As New Net.WebClient() Private Delegate Sub MyDelPtr() Public Extention As String = ".cfm" Const WebSite As String = "http://MyWebsite.com/" Public Sub Launch() ExplorePathThread(Threading.Thread.CurrentThread.Name) End Sub Private Sub ExplorePathThread(ByVal RequestString As String, Optional ByVal LastAscii As Integer = 0) Debug.WriteLine("Starting Thread: " & Threading.Thread.CurrentThread.Name) Application.DoEvents() Dim MyThreadClass As New ThreadClass MyThreadClass.CallBack = CallBack Dim MyDel1 = New MyDelPtr(AddressOf MyThreadClass.AddListItem1) Dim MyDel2 = New MyDelPtr(AddressOf MyThreadClass.AddListItem2) Dim Data As Byte() = Nothing Dim NumberOfFilesFound As Integer = 0 Dim DataLength As Integer = 0 NumberOfFilesFound = 0 Debug.WriteLine("Trying: " & WebSite & RequestString & "<" & Extention) Try If LastAscii = 0 Then Data = MyWebRequest.DownloadData(WebSite & RequestString & "<" & Extention) Else Data = MyWebRequest.DownloadData(WebSite & RequestString & Chr(LastAscii) & "<" & Extention) End If If DataLength <> Data.Length Then If LastAscii = 0 Then MyThreadClass.Data = (RequestString & "<" & Extention) CallBack.Invoke(MyDel1) Else MyThreadClass.Data = (RequestString & Chr(LastAscii) & "<" & Extention) CallBack.Invoke(MyDel1) Try MyWebRequest.DownloadData(WebSite & RequestString & Chr(LastAscii) & Extention) MyThreadClass.Data = ("--[" & RequestString & Chr(LastAscii) & Extention & "]--") CallBack.Invoke(MyDel2) Catch ex As Exception End Try ExplorePathThread(RequestString & ChrW(LastAscii), 48) End If End If Catch ex As Exception DataLength = 0 End Try Select Case LastAscii Case 0 LastAscii = 48 Case 58 LastAscii = 65 'A Case 91 LastAscii = 48 'Zero Return Case Else LastAscii += 1 End Select ExplorePathThread(RequestString, LastAscii) End Sub End Class |
Impact to WiFi Stability issues in NONOS sdk 2.1.0->2.2.0+
I’ve been on 2.1.0 for quite sometime and decided to take the leap to 3.0.0. After I did I started experiencing intermittent connection issues with my Wifi. Then also creating a snapshot I moved back to 2.1.0 and everything works great again. I also tested 3.0.1 and 3.0.2 and all yield the same issue and rolling back to 2.1.0 everything works. Does this having something to do with the new RF_CAL param added in userland or something else I may be missing from my upgrade? Any help would be amazing as I am currently stuck in the water right now …
How much power can I get out of an RS232 Port, Umm about 5-10MA on a good day
https://www.epanorama.net/circuits/rspower.html
Simple VB Webserver Spider
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 |
Public Class Form1 Public WithEvents MyClient As System.Net.WebClient Public TotalWorkingThreads As Integer = 0 Public TotalTags As Integer = 0 Public gExtractedLinks(50000) As String Private Sub SpiderThePageCache(ByVal Webpage As String) MyClient = New System.Net.WebClient Dim WebpageDocument As String = MyClient.DownloadString(Webpage) Dim AhrefIndex As Integer = 0 Dim ExtractedLink As String Dim ExtractedLinks(5000) As String Dim Flag As Boolean = False While True Flag = False AhrefIndex = WebpageDocument.IndexOf("a href", AhrefIndex) If AhrefIndex = -1 Then Exit While If WebpageDocument.Chars(AhrefIndex + 8) = "#" Then AhrefIndex += 8 Continue While End If ExtractedLink = vbNullString For i = (AhrefIndex + 8) To WebpageDocument.Length - 1 ' (AhrefIndex + 25) If WebpageDocument.Chars(i) = Chr(34) Then Exit For ExtractedLink &= WebpageDocument.Chars(i) Next Debug.WriteLine(AhrefIndex & " : " & ExtractedLink) For i = 0 To ExtractedLinks.Length If ExtractedLinks(i) = ExtractedLink Then Flag = True Exit For End If If ExtractedLinks(i) = Nothing Then Exit For End If Next If Flag = False Then For i = 0 To ExtractedLinks.Length If ExtractedLinks(i) = Nothing Then ExtractedLinks(i) = ExtractedLink Exit For End If Next End If AhrefIndex += 8 End While End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click 'SpiderThePage("Http://WebsiteToAudit/") Dim SpiderClass = New SpideringThreads SpiderClass.CallBack = Me SpiderClass.Webpage = "Http://Ikenet" Dim T = New Threading.Thread(AddressOf SpiderClass.SpiderMainPageWithThreads) T.IsBackground = False T.Priority = Threading.ThreadPriority.Highest T.Start() End Sub Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load End Sub End Class Class SpideringThreads Public CallBack As Form1 Public WithEvents MyClient As System.Net.WebClient Delegate Sub MyDelPtr() Public Webpage As String Enum Marker AHref = 1 AutoComplete = 2 Three = 3 End Enum Public Sub SpiderMainPageWithThreads() MyClient = New System.Net.WebClient Dim WebpageDocument As String Try WebpageDocument = MyClient.DownloadString(Webpage) Catch ex As Exception 'ListBox2.Items.Add(Webpage) Dim MyGUIClass = New GUIThreads MyGUIClass.Data = Webpage CallBack.Invoke(New MyDelPtr(AddressOf MyGUIClass.Listbox2Add)) 'Invoke on main thread Exit Sub End Try If InStr(WebpageDocument, "PASSWORD=", CompareMethod.Text) > 0 Or InStr(WebpageDocument, "developer for debugging", CompareMethod.Text) > 0 Then 'ListBox1.Items.Add(Webpage) Dim MyGUIClass = New GUIThreads MyGUIClass.Data = Webpage CallBack.Invoke(New MyDelPtr(AddressOf MyGUIClass.Listbox1Add)) 'Invoke on main thread End If Dim MasterIndex As Integer = 0 Dim ExtractedLink As String Dim Marker1, Marker2 As Integer Dim MarkerPath As Marker = 0 While True Marker1 = WebpageDocument.IndexOf("a href=""", MasterIndex) Marker2 = WebpageDocument.IndexOf(".autocomplete(", MasterIndex) If Marker1 = -1 And Marker2 = -1 Then Exit While End If If Marker1 = -1 Then MasterIndex = Marker2 MarkerPath = Marker.AutoComplete ElseIf Marker2 = -1 Then MasterIndex = Marker1 MarkerPath = Marker.AHref Else If Marker1 > Marker2 And Marker2 <> -1 Then MasterIndex = Marker2 MarkerPath = Marker.AutoComplete ElseIf Marker2 > Marker1 And Marker1 <> -1 Then MasterIndex = Marker1 MarkerPath = Marker.AHref End If End If Dim JumpInteger As Integer = 0 Select Case MarkerPath Case Marker.AHref JumpInteger = 8 Case Marker.AutoComplete JumpInteger = 15 Case Marker.Three Debug.WriteLine("Marker 3") Case Else Debug.WriteLine("Unknown value") End Select If WebpageDocument.Chars(MasterIndex + JumpInteger) = "#" Then MasterIndex += JumpInteger Continue While End If ExtractedLink = vbNullString For i = (MasterIndex + JumpInteger) To WebpageDocument.Length - 1 ' (AhrefIndex + 25) If WebpageDocument.Chars(i) = Chr(34) Then If ExtractedLink = Nothing Then MasterIndex += JumpInteger Continue While End If Exit For End If ExtractedLink &= WebpageDocument.Chars(i) Next Debug.WriteLine(MasterIndex & " : " & ExtractedLink) If Not ExtractedLink.StartsWith("HTTP", True, Nothing) Then ExtractedLink = "Http://Ikenet/" & ExtractedLink Else If Not ExtractedLink.StartsWith("Http://Ikenet/", True, Nothing) Or Not ExtractedLink.StartsWith("Https://Ikenet/", True, Nothing) Then Debug.WriteLine("NOT IKENET") MasterIndex += 8 Continue While End If End If If AddStringToGArray(ExtractedLink) Then 'SpiderThePage(ExtractedLink) Dim MyTotalClass = New GUIThreads CallBack.Invoke(New MyDelPtr(AddressOf MyTotalClass.AddWorkingThreads)) CallBack.Invoke(New MyDelPtr(AddressOf MyTotalClass.AddTotal)) 'Invoke on main thread Dim Spider = New SpideringThreads Spider.Webpage = ExtractedLink Spider.CallBack = CallBack Dim T As New Threading.Thread(AddressOf Spider.SpiderNewPageWithThreads) T.Start() Else Debug.WriteLine("Skipped Dubbed: " & ExtractedLink) End If MasterIndex += JumpInteger End While End Sub Public Sub SpiderNewPageWithThreads() MyClient = New System.Net.WebClient Dim WebpageDocument As String Try WebpageDocument = MyClient.DownloadString(Webpage) Catch ex As Exception 'ListBox2.Items.Add(Webpage) Dim MyGUIClass = New GUIThreads If ex.Message = "The remote server returned an error: (500) Internal Server Error." Then MyGUIClass.Data = Webpage CallBack.Invoke(New MyDelPtr(AddressOf MyGUIClass.Listbox1Add)) 'Invoke on main thread Exit Sub End If MyGUIClass.Data = Webpage CallBack.Invoke(New MyDelPtr(AddressOf MyGUIClass.Listbox2Add)) 'Invoke on main thread Exit Sub End Try If InStr(WebpageDocument, "PASSWORD=", CompareMethod.Text) > 0 Or InStr(WebpageDocument, "developer for debugging", CompareMethod.Text) > 0 Then 'ListBox1.Items.Add(Webpage) Dim MyGUIClass = New GUIThreads MyGUIClass.Data = Webpage CallBack.Invoke(New MyDelPtr(AddressOf MyGUIClass.Listbox1Add)) 'Invoke on main thread End If Dim AhrefIndex As Integer = 0 Dim ExtractedLink As String While True AhrefIndex = WebpageDocument.IndexOf("a href", AhrefIndex) If AhrefIndex = -1 Then Exit While If WebpageDocument.Chars(AhrefIndex + 8) = "#" Then AhrefIndex += 8 Continue While End If ExtractedLink = vbNullString For i = (AhrefIndex + 8) To WebpageDocument.Length - 1 ' (AhrefIndex + 25) If WebpageDocument.Chars(i) = Chr(34) Then If ExtractedLink = Nothing Then AhrefIndex += 8 Continue While End If Exit For End If ExtractedLink &= WebpageDocument.Chars(i) Next Debug.WriteLine(AhrefIndex & " : " & ExtractedLink) If Not ExtractedLink.StartsWith("HTTP", True, Nothing) Then ExtractedLink = "Http://Ikenet/" & ExtractedLink Else If Not ExtractedLink.StartsWith("Http://Ikenet/", True, Nothing) Or Not ExtractedLink.StartsWith("Https://Ikenet/", True, Nothing) Then Debug.WriteLine("NOT IKENET") AhrefIndex += 8 Continue While End If End If If AddStringToGArray(ExtractedLink) Then Dim MyTotalClass = New GUIThreads CallBack.Invoke(New MyDelPtr(AddressOf MyTotalClass.AddTotal)) 'Invoke on main thread SpiderThePage(ExtractedLink) Else Debug.WriteLine("Skipped Dubbed: " & ExtractedLink) End If AhrefIndex += 8 End While End Sub Public Sub SpiderThePage(ByVal WebSite As String) MyClient = New System.Net.WebClient Dim WebSiteDocument As String Try WebSiteDocument = MyClient.DownloadString(WebSite) Catch ex As Exception 'ListBox2.Items.Add(WebSite) Dim MyGUIClass = New GUIThreads MyGUIClass.Data = WebSite CallBack.Invoke(New MyDelPtr(AddressOf MyGUIClass.Listbox2Add)) 'Invoke on main thread Exit Sub End Try If InStr(WebSiteDocument, "PASSWORD=", CompareMethod.Text) > 0 Or InStr(WebSiteDocument, "developer for debugging", CompareMethod.Text) > 0 Then 'ListBox1.Items.Add(WebSite) Dim MyGUIClass = New GUIThreads MyGUIClass.Data = WebSite CallBack.Invoke(New MyDelPtr(AddressOf MyGUIClass.Listbox1Add)) 'Invoke on main thread End If Dim AhrefIndex As Integer = 0 Dim ExtractedLink As String While True AhrefIndex = WebSiteDocument.IndexOf("a href", AhrefIndex) If AhrefIndex = -1 Then Exit While If WebSiteDocument.Chars(AhrefIndex + 8) = "#" Then AhrefIndex += 8 Continue While End If ExtractedLink = vbNullString For i = (AhrefIndex + 8) To WebSiteDocument.Length - 1 ' (AhrefIndex + 25) If WebSiteDocument.Chars(i) = Chr(34) Then If ExtractedLink = Nothing Then AhrefIndex += 8 Continue While End If Exit For End If ExtractedLink &= WebSiteDocument.Chars(i) Next Debug.WriteLine(AhrefIndex & " : " & ExtractedLink) If Not ExtractedLink.StartsWith("HTTP", True, Nothing) Then ExtractedLink = WebSite & ExtractedLink Else If Not ExtractedLink.StartsWith("Http://Ikenet/", True, Nothing) Or Not ExtractedLink.StartsWith("Https://Ikenet/", True, Nothing) Then Debug.WriteLine("NOT IKENET") AhrefIndex += 8 Continue While End If End If If AddStringToGArray(ExtractedLink) Then Dim MyTotalClass = New GUIThreads CallBack.Invoke(New MyDelPtr(AddressOf MyTotalClass.AddTotal)) 'Invoke on main thread SpiderThePage(ExtractedLink) Else Debug.WriteLine("Skipped Dubbed: " & ExtractedLink) End If AhrefIndex += 8 End While End Sub Private Function AddStringToGArray(ByVal Webpage As String) As Boolean For i = 0 To CallBack.gExtractedLinks.Length If CallBack.gExtractedLinks(i) = Webpage Then Return False Exit For End If If CallBack.gExtractedLinks(i) = Nothing Then CallBack.gExtractedLinks(i) = Webpage Return True End If Next Return True End Function End Class Class GUIThreads Public Data As String Public Sub Listbox1Add() Form1.ListBox1.Items.Add(Data) End Sub Public Sub Listbox2Add() Form1.ListBox2.Items.Add(Data) End Sub Public Sub AddTotal() Form1.TotalTags += 1 Form1.Text = "Working Threads : " & Form1.TotalWorkingThreads & "Total Spidered: " & Form1.TotalTags End Sub Public Sub AddWorkingThreads() Form1.TotalWorkingThreads += 1 Form1.Text = "Working Threads : " & Form1.TotalWorkingThreads & "Total Spidered: " & Form1.TotalTags End Sub End Class |
Using SnmpSharpNet
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 |
Imports SnmpSharpNet Public Class Form1 Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load walk() End Sub Private Sub getone() Dim host As String = "MyHostName" Dim community As String = "public" Dim requestOid() As String Dim result As Dictionary(Of Oid, AsnType) requestOid = New String() {"1.3.6.1.2.1.1.1.0", "1.3.6.1.2.1.1.2.0"} Dim snmp As SimpleSnmp = New SimpleSnmp(host, community) If Not snmp.Valid Then Console.WriteLine("Invalid hostname/community.") Exit Sub End If result = snmp.Get(SnmpVersion.Ver1, requestOid) If result IsNot Nothing Then Dim kvp As KeyValuePair(Of Oid, AsnType) For Each kvp In result Console.WriteLine("{0}: ({1}) {2}", kvp.Key.ToString(), SnmpConstants.GetTypeName(kvp.Value.Type), kvp.Value.ToString()) Next Else Console.WriteLine("No results received.") End If End Sub Private Sub GetBulk() Dim host As String = "MyHostName" Dim community As String = "public" Dim requestOid() As String Dim result As Dictionary(Of Oid, AsnType) Dim rootOid As Oid = New Oid("1.3.6.1.2.1.1") Dim nextOid As Oid = rootOid Dim keepGoing As Boolean = True requestOid = New String() {rootOid.ToString()} Dim snmp As SimpleSnmp = New SimpleSnmp(host, community) If Not snmp.Valid Then Console.WriteLine("Invalid hostname/community.") Exit Sub End If While keepGoing result = snmp.GetNext(SnmpVersion.Ver1, New String() {nextOid.ToString()}) If result IsNot Nothing Then Dim kvp As KeyValuePair(Of Oid, AsnType) For Each kvp In result If rootOid.IsRootOf(kvp.Key) Then Console.WriteLine("{0}: ({1}) {2}", kvp.Key.ToString(), SnmpConstants.GetTypeName(kvp.Value.Type), kvp.Value.ToString()) nextOid = kvp.Key Else keepGoing = False End If Next Else Console.WriteLine("No results received.") keepGoing = False End If End While End Sub Private Sub walk() Dim host As String = "LocalHost" Dim community As String = "public" Dim result As Dictionary(Of Oid, AsnType) Dim snmp As SimpleSnmp = New SimpleSnmp(host, community) If Not snmp.Valid Then Console.WriteLine("Invalid hostname/community.") Exit Sub End If result = snmp.Walk(SnmpVersion.Ver2, "1.3.6.1.2.1.1") If result IsNot Nothing Then Dim kvp As KeyValuePair(Of Oid, AsnType) For Each kvp In result Console.WriteLine("{0}: ({1}) {2}", kvp.Key.ToString(), SnmpConstants.GetTypeName(kvp.Value.Type), kvp.Value.ToString()) Next Else Console.WriteLine("No results received.") End If End Sub End Class |
A simple Form Designer in VB.NET, Allows for RunTime editing and saving
https://www.codeproject.com/Articles/1004699/VB-NET-runtime-control-designer-for-windows-forms
Detect and know when your workstation is locked with VB.net
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 |
Imports System.Timers Public Class WorkStationReader #Region "API Calls" Private Const DESKTOP_CREATEMENU As Int32 = &H4& Private Const DESKTOP_CREATEWINDOW As Int32 = &H2& Private Const DESKTOP_ENUMERATE As Int32 = &H40& Private Const DESKTOP_HOOKCONTROL As Int32 = &H8& Private Const DESKTOP_READOBJECTS As Int32 = &H1& Private Const DESKTOP_SWITCHDESKTOP As Int32 = &H100& Private Const DESKTOP_WRITEOBJECTS As Int32 = &H80& Private Const GENERIC_WRITE As Int32 = &H40000000 Private Const HWND_BROADCAST As Int32 = &HFFFF& Private Const WM_HOTKEY As Int32 = &H312 Private Const MOD_ALT As Int32 = &H1 Private Const MOD_CONTROL As Int32 = &H2 Private Const VK_DELETE As Int32 = &H2E Private Const UOI_NAME As Int32 = 2 Private Declare Function OpenDesktop Lib "user32" Alias "OpenDesktopA" (ByVal lpszDesktop As String, ByVal dwFlags As Int32, ByVal fInherit As Boolean, ByVal dwDesiredAccess As Int32) As Int32 Private Declare Function CloseDesktop Lib "user32" (ByVal hDesktop As Int32) As Int32 Private Declare Function SwitchDesktop Lib "user32" (ByVal hDesktop As Int32) As Int32 #End Region #Region "WorkStationReader Global Variables" Dim p_lngHwnd As Int32 Dim p_lngRtn As Int32 Dim p_lngErr As Int32 Dim l_lkwkst As Int32 Dim MyTimer As New Timer() Public Sub New() MyTimer.Enabled = True MyTimer.Interval = 500 AddHandler MyTimer.Elapsed, New ElapsedEventHandler(AddressOf WorkStationISLocked) MyTimer.Start() End Sub #End Region #Region "WorkStationReader Events" Event locked(ByVal ivarreturn As Object) Event unlocked(ByVal ivarreturn As Object) #End Region Dim LastStateUnlocked As Boolean = True #Region "WorkStationReader Functions" Function WorkStationISLocked() As Object Dim ivarreturn(2) As Object p_lngHwnd = OpenDesktop("Default", 0, False, DESKTOP_SWITCHDESKTOP) If p_lngHwnd = 0 Then ivarreturn(0) = "Error with OpenDesktop: " & Err.LastDllError ivarreturn(1) = False WorkStationISLocked = ivarreturn If LastStateUnlocked Then RaiseEvent locked(ivarreturn) LastStateUnlocked = False End If Exit Function Else p_lngRtn = SwitchDesktop(hDesktop:=p_lngHwnd) p_lngErr = Err.LastDllError If p_lngRtn = 0 Then If p_lngErr = 0 Then 'ivarreturn(0) = "Desktop is locked: " & Err.LastDllError ivarreturn(0) = "Locked : " '& Err.LastDllError ivarreturn(1) = True WorkStationISLocked = ivarreturn If LastStateUnlocked Then RaiseEvent locked(ivarreturn) LastStateUnlocked = False End If GoTo CleanUpProc Else ivarreturn(0) = "Error with SwitchDesktop: " & Err.LastDllError ivarreturn(1) = False WorkStationISLocked = ivarreturn GoTo CleanUpProc End If Else 'ivarreturn(0) = "Not locked!" ivarreturn(0) = "Unlocked : " ivarreturn(1) = False WorkStationISLocked = ivarreturn If Not LastStateUnlocked Then RaiseEvent unlocked(ivarreturn) LastStateUnlocked = True End If GoTo CleanUpProc End If End If Exit Function CleanUpProc: p_lngHwnd = CloseDesktop(p_lngHwnd) End Function #End Region End Class Public Class Form1 WithEvents NewStation As New WorkStationReader() Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load End Sub Private Sub NewStation_locked(ivarreturn As Object) Handles NewStation.locked Debug.WriteLine("Locked - " & Now) End Sub Private Sub NewStation_unlocked(ivarreturn As Object) Handles NewStation.unlocked Debug.WriteLine("unLocked - " & Now) End Sub End Class |
C#
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 |
public class WorkStationReader { private const Int32 DESKTOP_CREATEMENU = 0x4; private const Int32 DESKTOP_CREATEWINDOW = 0x2; private const Int32 DESKTOP_ENUMERATE = 0x40; private const Int32 DESKTOP_HOOKCONTROL = 0x8; private const Int32 DESKTOP_READOBJECTS = 0x1; private const Int32 DESKTOP_SWITCHDESKTOP = 0x100; private const Int32 DESKTOP_WRITEOBJECTS = 0x80; private const Int32 GENERIC_WRITE = 0x40000000; private const Int32 HWND_BROADCAST = 0xFFFF; private const Int32 WM_HOTKEY = 0x312; private const Int32 MOD_ALT = 0x1; private const Int32 MOD_CONTROL = 0x2; private const Int32 VK_DELETE = 0x2E; private const Int32 UOI_NAME = 2; [System.Runtime.InteropServices.DllImport("user32")] private static extern Int32 OpenDesktop(string lpszDesktop, Int32 dwFlags, bool fInherit, Int32 dwDesiredAccess); [System.Runtime.InteropServices.DllImport("user32")] private static extern Int32 CloseDesktop(Int32 hDesktop); [System.Runtime.InteropServices.DllImport("user32")] private static extern Int32 SwitchDesktop(Int32 hDesktop); private Int32 p_lngHwnd; private Int32 p_lngRtn; private Int32 p_lngErr; private Int32 l_lkwkst; private Timer MyTimer = new Timer(); public WorkStationReader() { MyTimer.Enabled = true; MyTimer.Interval = 500; MyTimer.Elapsed += new ElapsedEventHandler(WorkStationISLocked); MyTimer.Start(); } public event lockedEventHandler locked; public delegate void lockedEventHandler(object ivarreturn); public event unlockedEventHandler unlocked; public delegate void unlockedEventHandler(object ivarreturn); private bool LastStateUnlocked = true; private void WorkStationISLocked(Object source, System.Timers.ElapsedEventArgs e) { object[] ivarreturn = new object[3]; p_lngHwnd = OpenDesktop("Default", 0, false, DESKTOP_SWITCHDESKTOP); if (p_lngHwnd == 0) { ivarreturn[0] = "Error with OpenDesktop: " + System.Runtime.InteropServices.Marshal.GetLastWin32Error(); ivarreturn[1] = false; if (LastStateUnlocked) { locked?.Invoke(ivarreturn); LastStateUnlocked = false; } return; } else { p_lngRtn = SwitchDesktop(hDesktop: p_lngHwnd); p_lngErr = System.Runtime.InteropServices.Marshal.GetLastWin32Error(); if (p_lngRtn == 0) { if (p_lngErr == 0) { // ivarreturn(0) = "Desktop is locked: " & Err.LastDllError ivarreturn[0] = "Locked : "; // & Err.LastDllError ivarreturn[1] = true; if (LastStateUnlocked) { locked?.Invoke(ivarreturn); LastStateUnlocked = false; } goto CleanUpProc; } else { ivarreturn[0] = "Error with SwitchDesktop: " + System.Runtime.InteropServices.Marshal.GetLastWin32Error(); ivarreturn[1] = false; goto CleanUpProc; } } else { // ivarreturn(0) = "Not locked!" ivarreturn[0] = "Unlocked : "; ivarreturn[1] = false; if (!LastStateUnlocked) { unlocked?.Invoke(ivarreturn); LastStateUnlocked = true; } goto CleanUpProc; } } return; CleanUpProc: ; p_lngHwnd = CloseDesktop(p_lngHwnd); return; } } public WorkStationReader MyStationLockWatcher = new WorkStationReader(); private void ThisAddIn_Startup(object sender, System.EventArgs e) { MyStationLockWatcher.locked += MyStationLockWatcher_locked; MyStationLockWatcher.unlocked += MyStationLockWatcher_unlocked; } private void MyStationLockWatcher_unlocked(object ivarreturn) { Debug.WriteLine("Unlocked"); } private void MyStationLockWatcher_locked(object ivarreturn) { Debug.WriteLine("Locked"); } |
Outlook Plugin to Track Jabber and Jira.
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 |
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Xml.Linq; using Outlook = Microsoft.Office.Interop.Outlook; using Office = Microsoft.Office.Core; using System.Windows.Forms; using System.Runtime.InteropServices; using System.DirectoryServices.AccountManagement; using System.DirectoryServices; using System.Collections; using System.Xml; using System.Xml.XPath; using System.Net; using System.Diagnostics; using System.Text.RegularExpressions; namespace EmailManager { public partial class ThisAddIn { Timer MyTimer = new Timer(); private void ClearCalendarAudits() { try { Outlook.Folder calFolder = Application.Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderCalendar) as Outlook.Folder; DateTime start = DateTime.Now.AddDays(-7); DateTime end = DateTime.Now; Outlook.Items rangeAppts = GetAppointmentsInRange(calFolder, start, end); if (rangeAppts != null) { foreach (Outlook.AppointmentItem appt in rangeAppts) { //Debug.WriteLine(DateTime.Now.ToString() + " - " +"Subject: " + appt.Subject + " Start: " + appt.Start.ToString("g")); if (appt.Subject.StartsWith(" IS-")) { System.Diagnostics.Debug.WriteLine(DateTime.Now.ToString() + " - " +appt.Start + " - " + appt.Subject + " Found !"); appt.Delete(); } } } } catch { } } private void JiraToCalendar(string LogItemsCount) { Log[] ActivityLog = GetJiraActivity("EID", LogItemsCount); if (ActivityLog == null) { return; } foreach (var MyLog in ActivityLog) { //Debug.WriteLine(DateTime.Now.ToString() + " - " +DateTime.Parse(MyLog.Published, System.Globalization.CultureInfo.InvariantCulture) + " - " + MyLog.Summary + " - " + MyLog.Ticket); if (!AddAppointment(" " + MyLog.Ticket + " - " + MyLog.Summary, DateTime.Parse(MyLog.Published, System.Globalization.CultureInfo.InvariantCulture).AddMinutes(-15))) //Adjust the 15s to show work in the past { //break; } } } private void TimerCount_Tick(System.Object sender, System.EventArgs e) { JiraToCalendar("10"); } private void ThisAddIn_Startup(object sender, System.EventArgs e) { ServicePointManager.ServerCertificateValidationCallback = AcceptAllCertifications; ServicePointManager.Expect100Continue = true; ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12; MarkEmailsAsHuman(); MyTimer.Interval = 60000 * 3; MyTimer.Tick += TimerCount_Tick; MyTimer.Start(); //ClearCalendarAudits(); JiraToCalendar("30"); //this.Application.NewMail += new Microsoft.Office.Interop.Outlook.ApplicationEvents_11_NewMailEventHandler(_NewMail); this.Application.NewMailEx += new Microsoft.Office.Interop.Outlook.ApplicationEvents_11_NewMailExEventHandler(Application_NewMailEx); ListenForRawData(); } private void ThisAddIn_Shutdown(object sender, System.EventArgs e) { // Note: Outlook no longer raises this event. If you have code that // must run when Outlook shuts down, see https://go.microsoft.com/fwlink/?LinkId=506785 } private bool AddAppointment(string subject, DateTime StartDate) { try { Outlook.Folder calFolder = Application.Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderCalendar) as Outlook.Folder; DateTime start = StartDate.AddMinutes(-10); //Cloup updates together between DateTime end = start.AddMinutes(45); Outlook.Items rangeAppts = GetAppointmentsInRange(calFolder, start, end); if (rangeAppts != null) { foreach (Outlook.AppointmentItem appt in rangeAppts) { //Debug.WriteLine(DateTime.Now.ToString() + " - " +"Subject: " + appt.Subject + " Start: " + appt.Start.ToString("g")); if (appt.Subject == subject) { System.Diagnostics.Debug.WriteLine("\t" + DateTime.Now.ToString() + " - " +appt.Subject + " Already exist!"); return false; //Cant tell the difference between a duped and clumped work. need to add a UID } } } } catch { } try { Outlook.AppointmentItem newAppointment = (Outlook.AppointmentItem)this.Application.CreateItem(Outlook.OlItemType.olAppointmentItem); newAppointment.Start = StartDate; newAppointment.End = StartDate.AddMinutes(15); newAppointment.Location = "N/A"; newAppointment.Body = ""; newAppointment.AllDayEvent = false; newAppointment.Subject = subject; newAppointment.ReminderSet = false; newAppointment.Categories = "Jira"; newAppointment.Sensitivity = Outlook.OlSensitivity.olPrivate; /* newAppointment.Recipients.Add("Roger Harui"); * Outlook.Recipients sentTo = newAppointment.Recipients; Outlook.Recipient sentInvite = null; sentInvite = sentTo.Add("Holly Holt"); sentInvite.Type = (int)Outlook.OlMeetingRecipientType .olRequired; sentInvite = sentTo.Add("David Junca "); sentInvite.Type = (int)Outlook.OlMeetingRecipientType .olOptional; sentTo.ResolveAll(); */ newAppointment.Save(); //newAppointment.Display(true); } catch (Exception ex) { MessageBox.Show("The following error occurred: " + ex.Message); } return true; } private bool AddCallLog(string subject, double seconds) { DateTime start = DateTime.Now.AddSeconds(-seconds); //Watch this, it seems to be multiplying and not adding DateTime end = DateTime.Now; try { Outlook.Folder calFolder = Application.Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderCalendar) as Outlook.Folder; Outlook.Items rangeAppts = GetAppointmentsInRange(calFolder, start, end); if (rangeAppts != null) { foreach (Outlook.AppointmentItem appt in rangeAppts) { //Debug.WriteLine(DateTime.Now.ToString() + " - " +"Subject: " + appt.Subject + " Start: " + appt.Start.ToString("g")); if (appt.Subject == subject) { System.Diagnostics.Debug.WriteLine("\t" + DateTime.Now.ToString() + " - " +appt.Subject + " Already exist!"); return false; //Cant tell the difference between a duped and clumped work. need to add a UID } } } } catch { } try { Outlook.AppointmentItem newAppointment = (Outlook.AppointmentItem)this.Application.CreateItem(Outlook.OlItemType.olAppointmentItem); newAppointment.Start = start; newAppointment.End = end; newAppointment.Location = "N/A"; newAppointment.Body = ""; newAppointment.AllDayEvent = false; newAppointment.Subject = subject; newAppointment.ReminderSet = false; newAppointment.Categories = "PhoneCall"; newAppointment.Sensitivity = Outlook.OlSensitivity.olPrivate; newAppointment.Save(); //newAppointment.Display(true); } catch (Exception ex) { MessageBox.Show("The following error occurred: " + ex.Message); } return true; } private Outlook.Items GetAppointmentsInRange(Outlook.Folder folder, DateTime startTime, DateTime endTime) { string filter = "[Start] >= '" + startTime.ToString("g") + "' AND [End] <= '" + endTime.ToString("g") + "'"; Debug.WriteLine(DateTime.Now.ToString() + " - " +filter); try { Outlook.Items calItems = folder.Items; calItems.IncludeRecurrences = true; calItems.Sort("[Start]", Type.Missing); Outlook.Items restrictItems = calItems.Restrict(filter); if (restrictItems.Count > 0) { return restrictItems; } else { return null; } } catch { return null; } } ArrayList Humans = new ArrayList(); ArrayList NonHumans = new ArrayList(); object Item = null; Outlook._MailItem moveMail = null; Outlook.Items resultItems = null; private void Application_NewMailEx(string EntryIDCollection) { /*string senderEmailid = string.Empty; Outlook.NameSpace outlookNameSpace = this.Application.GetNamespace("MAPI"); Outlook.Application myApp = new Outlook.Application(); Outlook.NameSpace mapiNameSpace = myApp.GetNamespace("MAPI"); Outlook.MAPIFolder myInbox = mapiNameSpace.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox); Outlook.Attachments attachments; int test = myInbox.Items.Count; */ object Item = Application.Session.GetItemFromID(EntryIDCollection, Type.Missing) as Outlook.MailItem; if (Item is Outlook._MailItem) { ProcessMailItem(Item as Outlook.MailItem); } } private void MarkEmailsAsHuman() { Outlook.MAPIFolder inBox = (Outlook.MAPIFolder) this.Application.ActiveExplorer().Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox); Outlook.Items inboxitems = (Outlook.Items)inBox.Items; //sFilter = "[LastModificationTime] > '" & Format("1/15/99 3:30pm", "ddddd h:nn AMPM") & "'" //items.Restrict("[UnRead] = true"); //Outlook.MAPIFolder destFolder = inBox.Folders ["Inbox"]; //Outlook.MAPIFolder destFolder = this.Application.ActiveExplorer().Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox); string Restricting = "([LastModificationTime] > '" + DateTime.Now.AddDays(-2).ToString("yyyy-MM-dd HH:mm") + "' or [ReceivedTime] > '" + DateTime.Now.AddDays(-2).ToString("yyyy-MM-dd HH:mm") + "')"; //string Restricting = "[UnRead] = true and ([LastModificationTime] > '" + DateTime.Now.AddDays(-2).ToString("yyyy-MM-dd HH:mm") + "' or [ReceivedTime] > '" + DateTime.Now.AddDays(-2).ToString("yyyy-MM-dd HH:mm") + "')"; //string Restricting = "[UnRead] = true"; resultItems = inboxitems.Restrict(Restricting); //Dictionary<string, string> SenderToAD = new Dictionary<string, string>(); Item = resultItems.GetFirst(); while (Item != null) { if (Item is Outlook._MailItem) { ProcessMailItem(Item as Outlook.MailItem); } Marshal.ReleaseComObject(Item); Item = resultItems.GetNext(); } /* foreach (object eMail in resultItems) { moveMail = eMail as Outlook.MailItem; try { if (!(moveMail is null)) { System.Diagnostics.Debug.WriteLine(DateTime.Now.ToString() + " - " +moveMail.UnRead + " " + moveMail.ReceivedTime + " / " + moveMail.LastModificationTime + " - " + (string)moveMail.SenderEmailAddress + " " + (string)moveMail.Subject); //if (!(moveMail.ReceivedTime is null)) //{ if (moveMail.ReceivedTime > (DateTime.Now.AddDays(-2))) { if (!(moveMail.Subject is null)) { if (moveMail.SenderEmailAddress.StartsWith("/O=EISENHOWER MEDICAL CENTER", StringComparison.OrdinalIgnoreCase)) { if (!(moveMail.Categories is null)) { System.Diagnostics.Debug.WriteLine(DateTime.Now.ToString() + " - " +moveMail.Categories); } if (moveMail.Categories != "Human") { moveMail.Categories = "Human"; moveMail.Save(); } //string titleSubject = (string)moveMail.Subject; } } } else { //return; } //} } } catch (Exception ex) { return; MessageBox.Show(ex.Message); if (ex.Message.StartsWith("Out of memory or system resources", StringComparison.OrdinalIgnoreCase)) { Application.Quit(); } } } */ } private void ProcessMailItem(Outlook.MailItem Item) { if (Item is Outlook._MailItem) { moveMail = Item as Outlook.MailItem; if (Humans.Contains(moveMail.SenderEmailAddress)) { if (moveMail.Categories != "Human") { moveMail.Categories = "Human"; moveMail.Save(); } return; } if (NonHumans.Contains(moveMail.SenderEmailAddress)) { return; } Outlook.Recipient recipient = moveMail.Application.Session.CreateRecipient(moveMail |