Know How Many Users Have Connected to My Computer in the Last Week, and How Many Time Has Been Connected Each One

Pandas count how many users connected to each computer

Use GroupBy.transform with DataFrameGroupBy.nunique, for count only Success rows repalce not matched User to missing values by Series.where:

print (df)
Computer User Type
0 computer1 user1 Fail
1 computer1 user2 Success
2 computer1 user3 Fail
3 computer2 user1 Success
4 computer2 user1 Fail
5 computer3 user1 Success
6 computer3 user2 Fail
7 computer3 user2 Success

df['User_Count'] = df.groupby('Computer')['User'].transform('nunique')

df['User_Count_Success'] = (df['User'].where(df['Type'].eq('Success'))
.groupby(df['Computer'])
.transform('nunique'))
print (df)
Computer User Type User_Count User_Count_Success
0 computer1 user1 Fail 3 1
1 computer1 user2 Success 3 1
2 computer1 user3 Fail 3 1
3 computer2 user1 Success 1 1
4 computer2 user1 Fail 1 1
5 computer3 user1 Success 2 2
6 computer3 user2 Fail 2 2
7 computer3 user2 Success 2 2

Details:

print (df['User'].where(df['Type'].eq('Success')))
0 NaN
1 user2
2 NaN
3 user1
4 NaN
5 user1
6 NaN
7 user2
Name: User, dtype: object

Getting number of times user logged in UNIX

If you want count of how many times a user logged in,then its not possible through command-line IMO....specifically because there is sudo option to pretend other user which can fail your logic - if you have any

Also, how many times needs to have a time bracket (from when till when)..so you need to have an upper time bracket as well from which you want to track down the count.All this would be a mess ideally just to maintain a count

If i have to keep track of it, my best guess would be to have a script and maintain a db-table keeping the count of users who are logging-in!

The request was aborted: Could not create SSL/TLS secure channel

I finally found the answer (I haven't noted my source but it was from a search);

While the code works in Windows XP, in Windows 7, you must add this at the beginning:

// using System.Net;
ServicePointManager.Expect100Continue = true;
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
// Use SecurityProtocolType.Ssl3 if needed for compatibility reasons

And now, it works perfectly.


ADDENDUM

As mentioned by Robin French; if you are getting this problem while configuring PayPal, please note that they won't support SSL3 starting by December, 3rd 2018. You'll need to use TLS. Here's Paypal page about it.

Powershell - Find computers with a specific username logged in

Continuing from my comment. . .

Here's an quick and dirty approach you can take:

Function Get-Username {
Clear-Host
$Global:Username = Read-Host "Enter Username"
if ($Username -eq $null){
Write-Host "Username cannot be blank, please enter a Username"
Get-Username
}
$UserCheck = Get-ADUser $Username
if ($UserCheck -eq $null){
Write-Host "Invalid Username, please verify this is the logon id for the account"
Get-Username
}
}
Get-Username
Function Get-Computername {
Clear-Host
$Global:Prefix = Read-Host "Enter Computername"
Clear-Host
}
Get-Computername

$computers = Get-ADComputer -Filter {Enabled -eq $true -and SamAccountName -like $Prefix}

$check = Get-CimInstance -Query "SELECT Name,UserName from Win32_ComputerSystem WHERE UserName LIKE '%$userName%'" `
-ComputerName $Computers.Name`
-ErrorAction SilentlyContinue
if ($check) {
# $check.UserName/Name may return an array same name users are found.
Write-Output -InputObject ($check.UserName + " is logged into: " + $check.Name)
}
else {
Write-Output -InputObject "Unable to find $userName."
}

Seeing as you're not doing nothing with the systems that you're unable to ping, you can silence the output and only returning the results for the ones that are online. Best solution for you scenario and question, is to take advantage of the parallelization that Get-CIMInstance allows you to do when passing an array of computers to -ComputerName.

  • Write-Progress tends to be terribly slow and if you're looking for a fast solution, this will definitely slow you down.
  • Get-WMIObject is a deprecated cmdlet that has been superseded by Get-CIMInstance which offers the same functionality, with a safer remoting procedure.
  • Using -Query, we can use WQL to search at the time of query speeding up the process some more. The only downside to some admins is that it follows its own syntax.

One thing to note, if you can ping a machine, it doesn't mean you can connect to it.

How do you detect a VPN or Proxy connection?

Unfortunately, there's is no proper technical way to get the information you want. You might invent some tests, but those will have a very low correlation with the reality. So either you'll not catch those you want, or you'll have a larger number of false positives. Neither can be considered to make sense.

Generating any kind of traffic backwards from an Internet server in response to an incoming client (a port scan, or even a simple ping) is generally frowned upon. Or, in the case of a port scan, it may be even worse for you, eg when the client lives behind a central corporate firewall, the worst of which is when the client comes from behind the central government network firewall pool...

Frankly, IP-based bans (or actually, any kind of limiting focusing on people who do not exclusively possess their public IP address: proxy servers, VPNs, NAT devices, etc) have been unrealistic for a long time, and as the IPv4 pools have been getting depleted in many parts of the world, ISPs are putting more and more clients behind large NAT pools (it's this week's news in my country that the largest ISP, a subsidiary of Deutsche Telekom, has started handing out private IPv4 addresses as a standard way of business to its customers, and people have to ask the provider explicitly to get a public IP address), so there's even less and less point in doing so. If you want to ban clients, you should ban them based on identity (account), and not based on IP address.

Log a user out of a website when they put their computer to sleep

UPDATE

Regarding the WebSocket request, I assume you're using Laravel WebSockets with pusher. Pusher.io does not support timeout, you can read this support article "Do you plan to add a connection timeout feature to the Channels pusher-js client library?". You can test it out if you enable Laravel debug mode (APP_DEBUG=true inside .env) and beggin laravel-websockets from terminal (php artisan websockets:serve) so you can see the output log events. If you try to close the laptop lid or set computer to hibernation mode (sleep), you won't see any messages regarding this event. You cannot do it with the pusher protocol. There is the member_removed Presence event, but that triggers only when you close the tab or you logout. Of course you can trigger your client custom event to the presence channel, but to do that you also need a timer setup to the client side and you'll have to create a service provider for the laravel-websockets server like this github issue "Exist a way to implement webhooks?".

Some people have suggested in other similar questions:

...

  • To have a timer running on the front end (we do, it just stops when you close the laptop lid)

That happens because client timers halt execution on hibernation, thus they continue from where they were before. But if you use a date variable to save the time, that variable will not get updated when the computer goes to hibernation, thus you'll know when it goes out from sleep by checking that date variable which in compare to current time will have significant difference and will be greater than the timer interval.

Implementing time logic in client

You can also see this implementation to this related Q/A: Can any desktop browsers detect when the computer resumes from sleep?

You can setup a timer in the client to run each minute. We won't rely on the timer interval, but instead that timer will check an outer scope date variable if the time span since last timer is greater than 15 minutes; if it is, then that means that the browser/JS halted execution for some reason, possibly hibernation of the device (sleep) and then you redirect the user to the logout route.

Example JS client code:

// Set a variable to check previous time
let clientSession = new Date;

// Setup the client session checking timer
let clientSessionTimer = setInterval(() => {
const now = new Date;
// Get how many seconds have passed since last check
const secondsSpan = (now - clientSession) / 1000;

// If the 1 minute timer has exceeded 15 minutes trigger logout and clear timer
if (secondsSpan > (60 * 15)) {
// For some reason JS halted execution, so we'll proceed with logging out
clearInterval(clientSessionTimer);
window.location.href = '/logout/session'
} else {
// The timer runs as it should, update the clientSession time
clientSession = now;
}

}, 1000 * 60);

You can check this simple example but using 1 second timer with 15 seconds logout here. Best to test it on a laptop with closing the lid and then open it again after 15 seconds a minute of two, because if you have many programs running, the computer takes some time to save memory state so to complete hibernation mode and halt execution.

Web Workers Example

You can even use Web Workers API to setup a web worker to be much safer:

Page JS code:

const logoutWorker = new Worker('logoutWorker.js');
logoutWorker.onmessage = function (ev) {

if (ev && ev.data === 'wakeup') {
logoutWorker.terminate();
// window.location.href = '/logout/session'
} else {
// The timer runs as it should, nothing to do
}
}

Web worker logoutWorker.js code:

let clientSession = new Date();

let clientSessionTimer = setInterval(() => {
const now = new Date;
const secondsSpan = (now - clientSession) / 1000;

if (secondsSpan > 15) {
postMessage('wakeup'); // Send a message wakeup to the worker page
clearInterval(clientSessionTimer); // Clear the timer
} else {
clientSession = now; // Update the clientSession timer variable
postMessage('update'); // And post a message to the page ONLY IF needed
}
}, 1000);

You can also check the Web Worker example with the same 15 seconds timer here.



Related Topics



Leave a reply



Submit