hosts


Hosts examples
The examples in this folder focus on leveraging CrowdStrike's Hosts API to perform administrative operations.
Add Falcon Tags in bulk
Bulk assign a Falcon Grouping Tag to a list of hosts based on their serial number. This solution updates the tags of hosts in batches of 20.
Running the program
In order to run this demonstration, you will need access to CrowdStrike API keys with the following scopes:
Hosts
READ
Execution syntax
This samples leverages simple command-line arguments to implement functionality.
Execute the default example. This will assume the file containing serial numbers is called "serials.txt" and is stored in the same folder. That tag that will be added will have a value of "TEST_TAG".
This sample supports Environment Authentication, meaning you can execute any of the command lines shown below without providing credentials if you have the values
FALCON_CLIENT_IDandFALCON_CLIENT_SECRETdefined in your environment.
Read the file "new_serials.txt" and apply the tag "NEW_TAG" to all devices identified.
Remove the tag "NEW_TAG" from all hosts identified in the file "new_serials.txt".
API debugging can be enabled using the
-dargument.
Command-line help
Command-line help is available via the -h argument.
Example source code
The source code for these examples can be found here.
Default Groups
This script was developed to setup the default groups in a new CID. It should be run once to create the necessary groups and populate them with the appropriate assignment rules.
Note: This sample also demonstrates pythonic response handling using the Advanced Uber Class (APIHarnessV2).
Running the program
In order to run this demonstration, you will need access to CrowdStrike API keys with the following scopes:
Hosts
READ
[!IMPORTANT] This script should be reviewed and updated to match your environment needs. Review the
groupsdictionary to identify group names and assignment rules that will be created. (lines 89 - 102, shown below)
Execution syntax
This samples leverages simple command-line arguments to implement functionality.
Execute the default example. This will create the groups as defined by the
groupsdictionary within the current tenant (non-MSSP).
This sample supports Environment Authentication, meaning you can execute any of the command lines shown below without providing credentials if you have the values
FALCON_CLIENT_IDandFALCON_CLIENT_SECRETdefined in your environment.
Enable MSSP mode and create the groups within all child CIDs.
Enable MSSP mode and create the groups within a specific child CID.
API debugging can be enabled using the
-dargument.
Command-line help
Command-line help is available via the -h argument.
Example source code
The source code for these examples can be found here.
Get Host Groups
This script will output a list of all Host Groups, for Flight Control scenarios it will display all the host groups in all child CIDs.
Note: This sample also demonstrates pythonic response handling using the Advanced Uber Class (APIHarnessV2).
Running the program
In order to run this demonstration, you will need access to CrowdStrike API keys with the following scopes:
Hosts
READ
Execution syntax
This samples leverages simple command-line arguments to implement functionality.
Execute the default example. This will list all groups within the current tenant.
This sample supports Environment Authentication, meaning you can execute any of the command lines shown below without providing credentials if you have the values
FALCON_CLIENT_IDandFALCON_CLIENT_SECRETdefined in your environment.
Enable MSSP mode and list the groups within all child CIDs.
Enable MSSP mode and list the groups within a specific child CID.
Change the format of the output tabular display with the
-targument.
Accepted formats
The following table formats are supported:
plainsimplegithubgridsimple_gridrounded_gridheavy_gridmixed_griddouble_gridfancy_gridoutlinesimple_outlinerounded_outlineheavy_outlinemixed_outlinedouble_outlinefancy_outlinepipeorgtblasciidocjiraprestoprettypsqlrstmediawikimoinmoinyoutrackhtmlunsafehtmllatexlatex_rawlatex_booktabslatex_longtabletextiletsv
API debugging can be enabled using the
-dargument.
Command-line help
Command-line help is available via the -h argument.
Example source code
The source code for these examples can be found here.
Host Report
This script replaces the manual daily export of hosts from the Falcon Console that was required to audit host compliance. It was developed to be run as a recurring job and will output a CSV with all hosts in the CID along with other required info that can then be imported into a compliance dashboard or tool.
Running the program
In order to run this demonstration, you will need access to CrowdStrike API keys with the following scopes:
Hosts
READ
Execution syntax
This samples leverages simple command-line arguments to implement functionality.
Execute the default example. This will output results to a CSV file named
Hosts_output.csv.
This sample supports Environment Authentication, meaning you can execute any of the command lines shown below without providing credentials if you have the values
FALCON_CLIENT_IDandFALCON_CLIENT_SECRETdefined in your environment.
Change the output file with the
-oargument.
API debugging can be enabled using the
-dargument.
Command-line help
Command-line help is available via the -h argument.
Example source code
The source code for these examples can be found here.
Host Search
This script will take a file listing of hostnames (one host per line) or a single hostname provided at runtime to produce a CSV containing the details for hosts that are found. This solution can be used to compare a list of hostnames to the list of hosts in the Falcon Console to determine which hostnames are not currently reporting in to the console.
Running the program
In order to run this demonstration, you will need access to CrowdStrike API keys with the following scopes:
Hosts
READ
Execution syntax
This samples leverages simple command-line arguments to implement functionality.
Execute the default example. This will assume the file containing serial numbers is called "serials.txt" and is stored in the same folder. That tag that will be added will have a value of "TEST_TAG".
This sample supports Environment Authentication, meaning you can execute any of the command lines shown below without providing credentials if you have the values
FALCON_CLIENT_IDandFALCON_CLIENT_SECRETdefined in your environment.
Read the file "new_hosts.txt" and search for matches.
Search for the hostname
example-host.
Output results to a different CSV file.
API debugging can be enabled using the
-dargument.
Command-line help
Command-line help is available via the -h argument.
Example source code
The source code for these examples can be found here.
Host Search Advanced
This script retains the original functionality of host_search.py above, but adds in functionality for partial matches of hostnames. This will help with endpoint discovery where the domain is known, or a pattern of host naming is known, but not all endpoints have been discovered.
This script will also ignore comments in a hostname file, thus keeping the output.csv cleaner.
To read an input file of hostnames, the -f option (used in the original host_search.py) has been changed to -i. This made more sense considering the more "insensitive" nature of the search, and makes a visual identification of the full command easier if you use both the original host_search.py, and the host_search_advanced.py. A potential use case could be to discover hosts using the 'advanced' search, in order to reconcile with hostname files for use with the original host search.
Command-line help
Command-line help is available via the -h argument.
List sensors by hostname
Loops through all hosts and displays the hostname and sensor version.
There are multiple variations of this sample demonstrating different options for achieving the same goals.
Displays all hosts along with their sensor version. Maximum number of results returned: 10,000
Displays all hosts along with their sensor version. No maximum on number of hosts returned.
Displays all hosts along with their sensor version. No maximum on number of hosts returned. Leverages multiple threads to speed up results processing.
Running the program
In order to run this demonstration, you will need access to CrowdStrike API keys with the following scopes:
Hosts
READ
Execution syntax
These samples leverage simple command-line arguments to implement functionality.
All keywords are available in all three samples.
Execute the simple example.
Execute the scrolling example, reversing the sort.
Execute the advanced example and return results for a child tenant.
Execute the advanced example for a GovCloud tenant.
Command-line help
Command-line help is available via the -h argument.
Example source code
The source code for these examples can be found here:
List duplicate sensors
Retrieves a list of duplicate sensors across all hosts within your tenant. Can optionally hide (and then restore) duplicate sensors identified.
Running the program
In order to run this demonstration, you will need access to CrowdStrike API keys with the following scopes:
Hosts
READ, WRITE
Execution syntax
This application leverages easy to use command line arguments to implement functionality.
List just duplicate sensors.
Perform the same lookup against a tenant within GovCloud.
List all hosts (including duplicates).
Search a child tenant.
Hide duplicate sensors identified.
Restore previously removed duplicates.
Command-line help
Command-line help is available via the -h argument.
Example source code
The source code for this example can be found here.
List stale sensors
Retrieves a list of hosts that have not been seen since the number of days specified. Can optionally hide the hosts identified.
Running the program
In order to run this demonstration, you will need access to CrowdStrike API keys with the following scopes:
Hosts
READ, WRITE
Execution syntax
The following command will retrieve a list of hosts that haven't checked in to CrowdStrike in 30 days or more.
Perform the same lookup against a tenant within GovCloud.
This variation will retrieve a list of hosts that haven't checked in to CrowdStrike in 30 days or more that have the tag testtag.
This variation leverages a regular expression to match the host "SDKDEMO3".
You can reverse the list sort with the -r or --reverse argument.
The following command will hide any hosts that haven't checked in to CrowdStrike in 30 days or more. You may also use -x to accomplish this.
Command-line help
Command-line help is available via the -h argument.
Example source code
The source code for this example can be found here.
Policy Check
This program will check if a specific host group is properly assigned to a list of Prevention Policies.
Note: This sample also demonstrates pythonic response handling using the Advanced Uber Class (APIHarnessV2).
Running the program
In order to run this demonstration, you will need access to CrowdStrike API keys with the following scopes:
Hosts
READ
Execution syntax
This samples leverages simple command-line arguments to implement functionality.
Execute the default example. This will check within the local tenant that the group has the policies assigned listed in the
-pargument.
This sample supports Environment Authentication, meaning you can execute any of the command lines shown below without providing credentials if you have the values
FALCON_CLIENT_IDandFALCON_CLIENT_SECRETdefined in your environment.
Enable MSSP mode and create the groups within all child CIDs.
Enable MSSP mode and create the groups within a specific child CID.
API debugging can be enabled using the
-dargument.
Command-line help
Command-line help is available via the -h argument.
Example source code
The source code for these examples can be found here.
Match usernames to hosts
Submitted by @micgoetz, this example demonstrates leveraging the QueryDeviceLoginHistory method to identify the most common username for hosts within a Falcon tenant. Hosts are then tagged with a Falcon Grouping Tag to reflect this identified user.
Running the program.
In order to run this demonstration, you will need access to CrowdStrike API keys with the following scopes:
Hosts
READ, WRITE
Execution syntax
Generic execution.
Test the results of execution without taking action.
Load a username to host mapping file.
Remove grouping tags set by this routine.
Change your BASE_URL to point to GovCloud.
Command-line help
Command-line help is available via the -h argument.
Example source code
The source code for this example can be found here.
Comparing QueryDevicesByFilter and QueryDevicesByFilterScroll (Offset vs. Token)
This routine queries all of the hosts in your environment using the QueryDevicesByFilter and the QueryDevicesByFilterScroll operations. The results of the two methods are then compared for equivalency. This sample demonstrates how to use both operations to paginate through large result sets, and discusses the inherent limitations of the QueryDevicesByFilter operation.
Running the program.
In order to run this demonstration, you will need access to CrowdStrike API keys with the following scopes:
Hosts
READ
Execution syntax
This example requires no input parameters.
Example source code
The source code for this example can be found here.
Prune Hosts by Hostname or AID
Search for and optionally remove hosts by hostname or AID. Removed host AIDs are saved to a file which can be leveraged to restore removed hosts.
Running the program.
In order to run this demonstration, you will need access to CrowdStrike API keys with the following scopes:
Hosts
READ, WRITE
Execution syntax
List hosts by hostname or AID.
Remove identified hosts.
Restore previously deleted hosts from the restore file.
Restore previously deleted hosts by AID.
Change your BASE_URL to point to GovCloud.
Search a child tenant for hosts to remove.
Command-line help
Command-line help is available via the -h argument.
Example source code
The source code for this example can be found here.
RFM Report
This script determines the number of hosts in RFM (Up for more than 24 hours and seen within the last 24 hours) in your tenant or every child tenant attached to your parent.
Running the program
In order to run this demonstration, you will need access to CrowdStrike API keys with the following scopes:
Hosts
READ
Flight Control
READ (MSSP usage only)
Execution syntax
This samples leverages simple command-line arguments to implement functionality.
Execute the default example. This will output results for your tenant (only) to a CSV file called
RFM_Report.csv.
This sample supports Environment Authentication, meaning you can execute any of the command lines shown below without providing credentials if you have the values
FALCON_CLIENT_IDandFALCON_CLIENT_SECRETdefined in your environment.
The output file name can be changed using the
-oargument.
For MSSP scenarios, provide your parent credentials and activate MSSP mode with the
-margument.
API debugging can be enabled using the
-dargument.
Command-line help
Command-line help is available via the -h argument.
Example source code
The source code for these examples can be found here.
Serial Search
This script takes a file listing Serial Numbers and outputs a CSV with the Serial Number, Hostname, CID, RFM, Last Seen, Local IP, and Tags for each host in the list. This list can be used to compare a list of serial numbers to the list of hosts in the Falcon Console to determine which serial numbers are not currently reporting to the console.
Running the program
In order to run this demonstration, you will need access to CrowdStrike API keys with the following scopes:
Hosts
READ
Execution syntax
This samples leverages simple command-line arguments to implement functionality.
Execute the default example. This will output results to a CSV file named
output.csv.
This sample supports Environment Authentication, meaning you can execute any of the command lines shown below without providing credentials if you have the values
FALCON_CLIENT_IDandFALCON_CLIENT_SECRETdefined in your environment.
Change the output file with the
-oargument.
Change the input file containing the serials to search for using the
-fargument.
API debugging can be enabled using the
-dargument.
Command-line help
Command-line help is available via the -h argument.
Example source code
The source code for these examples can be found here.
Last updated
Was this helpful?