与Code42 API交互的工具
这篇文章是给谁看的?
老师,不。
Incydr Professional, Enterprise, Horizon和Gov F2,是的。
Incydr基础,高级和Gov F1,是的。
概述
Code42 API可以通过许多工具访问,例如web浏览器、脚本工具和编程语言。本文提供了指向第三方工具的链接,您可以使用这些工具与Code42 API进行交互。
注意事项
本文中的示例使用资源https://console.us.code42.com,但您使用的资源取决于您的Code42云主机地址:
第三方软件
本文提供了使用第三方软件与Code42 API交互的资源和基本用法示例。有关更详细的信息,请参阅软件制造商提供的文档。
Web浏览器
Code42 API是基于http的,所以你可以使用web浏览器与它交互:
脚本工具
为了编写Code42 API的脚本,使用curl和Windows PowerShell。当它们可以调用Python的json.tool时,两者都能工作得最好
Python的JSON.tool
json.tool是一个Python JSON编码器和解码器,可用于使Code42 API输出更具可读性。json。工具要求Python 3安装在系统上。
返回JSON而不是PowerShell对象
如果希望API命令返回JSON而不是PowerShell对象,请添加ConvertTo-Jsoncmdlet:
\ users \调用webrequest -Token < auth_token >
-URi https://console.us.code42.com/api/v1/Computer -Method Get | Select-Object Content | converto - json
本例中为replace< auth_token >
与一个身份验证令牌.
旋度
旋度是一个命令行工具,可用于通过多种协议(包括HTTP和HTTPS)提交和接收数据。
Linux和Mac
示例命令
下面的命令列出了Code42环境中的设备:
curl -X GET -k 'https://console.us.code42.com/api/v1/Computer' -H '授权:持有者< auth_token >
| python3 -mjson.tool
本例中为replace< auth_token >
与一个身份验证令牌.
有关其他示例,请参阅我们的Code42 API语法和用法篇文章。
窗户
安装Cygwin,它通过curl包为Windows提供了一个类似unix的命令行界面。当你奔跑安装程序,在选择包窗口确保选中旋度从内部网分类,并选择Python.
您可以在Windows上使用相同的开关运行curl示例。您不仅可以在Cygwin shell中运行curl,还可以在Windows中运行curlcmd如果您将Cygwin二进制路径添加到Windows,则会使用shell路径系统环境变量(例如,C: \ cygwin64 \ bin).
示例命令
下面的命令列出了Code42环境中的设备:
curl -X GET -k 'https://console.us.code42.com/api/v1/Computer' -H '授权:持有者< auth_token >
| python3 -mjson.tool
本例中为replace< auth_token >
与一个身份验证令牌.
有关其他示例,请参阅我们的Code42 API语法和用法篇文章。
从Code42控制台复制curl命令
Chrome和Firefox包含将网络请求复制为curl命令的选项。您可以使用此功能创建一个curl命令,该命令复制Code42控制台操作的功能。
- 使用Chrome或Firefox登录到Code42控制台。
- 导航到包含要复制的命令的页面。
- 打开Chrome或Firefox开发工具,然后单击网络.
- 在想要复制的Code42控制台中启动操作。
与该操作相对应的网络请求出现在开发人员工具中。 - 在开发人员工具中,右键单击网络请求,然后选择复制为cURL.
- 将复制的curl命令粘贴到文本编辑器中,并根据需要修改该命令。
Windows PowerShell
在Windows上与Code42 API的脚本交互依赖于PowerShellInvoke-RestMethod实用cmdlet。
- 在PowerShell 3.0及更高版本中可以使用Invoke-RestMethod。
- 返回值格式化为PowerShell对象。
示例命令
下面的命令列出了Code42环境中的设备:
Invoke-WebRequest令牌< auth_token >
-URi https://console.us.code42.com/api/v1/Computer -方法获取
本例中为replace< auth_token >
与一个身份验证令牌.
程序语言
Python
要在Python中与Code42 API交互,请使用请求图书馆.下面的示例使用请求来运行简单的得到方法。电脑资源。
请求必须是安装在执行示例之前。
脚本的例子
导入请求r = requests.get('https://console.us.code42.com/api/v1/Computer', auth=BearerAuth('< auth_token >
’))打印r.status_code打印r.text
本例中为replace< auth_token >
与一个身份验证令牌.
互动的例子
user@UbuntuLTS:~$ python python 2.7.6(默认,Mar 22 2014, 22:59:56) [GCC 4.8.2] on linux2输入“help”,“copyright”,“credits”或“license”以获取更多信息。>>>导入请求>>> r=requests.get('https://console.us.code42.com/api/v1/Computer', auth=BearerAuth(' https://console.us.code42.com/api/v1/Computer')< auth_token >
')) > > >打印r <反应> > > > r.text u '{“元数据”:{“时间戳”:“2015 - 03 - 27 - t12:19:27.632 -凌晨5”,“参数”:{}},“数据”:{“电脑”:[{“computerId”:13日,“名字”:“WIN-FQNN6BGK47K”、“guid”:“681099810721783680”、“类型”:“电脑”,“状态”:“活跃,Deauthorized”、“活跃”:真的,“封锁”:假的,”alertState”:0,”alertStates”:“OK”,“用户名”:2,“orgId”:2,“parentComputerId”:空,“lastConnected”:“2015 - 03 - 18 - t16:42:55.482凌晨”、“osName”:“赢”、“osVersion”:“6.2”,“osArch”:“amd64”、“地址”:“192.168.95.128:4242”、“remoteAddress”:“172.16.239.1”、“javaVersion”:“1.7.0_45”、“modelInfo”:空,“时区”:“美国/芝加哥”、“版本”:1388728800370,“productVersion”:“3.7.0”、“buildVersion”:空,“创建日期”:“2015 - 03 - 18 - t16:39:04.241凌晨”、“modificationDate”:“2015 - 03-24 t09:39:21.135-05:00”、“loginDate”:“2015 - 03 - 18 - t16:39:07.570凌晨”、“服务”:“Code42 "}, {" computerId ": 12,“名字”:“WIN-FQNN6BGK47K”、“guid”:“680201360538886016”、“类型”:“电脑”,“状态”:“活跃”,“活动”:真的,“封锁”:假的,“alertState”:0,“alertStates”:“OK”,“用户名”:2,“orgId”:2,“parentComputerId”:空,“lastConnected”:“2015 - 03 - 12 - t17:17:23.909凌晨”、“osName”:“赢”,“osVersion”:“6.2.9200.0”、“osArch”:空,“地址”:“192.168.95.128:4252”、“remoteAddress”:“172.16.239.1”、“javaVersion”:空,“modelInfo”:零,“时区”:空,“版本”:1413349200416,“productVersion”:“3.7.0”、“buildVersion”:31日“创建日期”:“2015 - 03 - 12 - t11:53:40.861凌晨”、“modificationDate”:“2015 - 03 - 12 - t17:17:23.909凌晨”、“loginDate”:“2015 - 03 - 12 - t16:23:12.272凌晨”,“服务”:“Code42”},{“computerId”:10“名称”:“WIN-FQNN6BGK47K”,“guid”:“680190841811656576”、“类型”:“电脑”,“状态”:“活跃”,“活动”:真的,“封锁”:假的,“alertState”:0,“alertStates”:“OK”,“用户名”:2,“orgId”:2,“parentComputerId”:空,“lastConnected”:“2015 - 03 - 13 - t13:15:49.352-05:00”、“osName”:“赢”、“osVersion”:“6.2.9200.0”、“osArch”:空,“地址”:“192.168.95.128:4252”、“remoteAddress”:“172.16.239.1”、“javaVersion”:空,“modelInfo”:空,“时区”:空,“版本”:1413349200416,“productVersion”:“3.7.0”、“buildVersion”:空,“创建日期”:“2015 - 03 - 12 - t11:51:13.871凌晨”、“modificationDate”:“2015 - 03 - 13 - t13:15:49.352凌晨”、“loginDate”:“2015 - 03 - 12 - t11:51:13.867凌晨”、“服务”:“Code42“}]}}
Ruby
要在Ruby中与Code42 API交互,请使用法拉第的宝石.下面的例子用法拉第来运行一个简单的得到方法。电脑资源。法拉第一定是安装在执行示例之前。
脚本的例子
require 'faraday' conn =法拉第。新的conn.authorization:持票人< auth_token >
' response = conn.get 'https://console.us.code42.com/api/v1/Computer'放置响应。Status放置response.body
本例中为replace< auth_token >
与一个身份验证令牌.
互动的例子
user@UbuntuLTS:~$ irb irb(main):001:0> require 'faraday' => true irb(main):002:0> conn =法拉第。new => #<:connection:0x00000001c359f0>"Faraday v0.9.1"}, @params={}, @options=#<:requestoptions>, @ssl=#<:ssloptions>, @default_parallel_manager=nil, @builder=#<:rackbuilder:0x00000001c354f0>, @url_prefix=#<:http:0x00000001fcffe8>, @proxy=nil> irb(main):003:0> conn.authorization:Bearer, '< auth_token >
' = >“基本YWRtaW46YWRtaW4 = " irb(主要):004:0 > conn.get ' https://console.us.code42.com/api/v1/Computer ' = > # <法拉第::响应:0 x00000002666528 @on_complete_callbacks = [], @env = # <中@ method =法拉第::Env: @body = "{\ \“元数据”:{\“时间戳\”,\“2015 - 03 - 27 - t12:53:50.741凌晨\”,\“params \”:{}},\“数据\”:{\电脑\”:[{\ \“computerId \”:13日,“名字\”:\“WIN-FQNN6BGK47K \”,\“guid \”,\“681099810721783680 \”,\“\”,\“电脑\”,\“\”,\“活跃,Deauthorized \”,\“活跃\”:真的,\“屏蔽\”:假的,\“alertState \”:0,\“alertStates \”,\“好的\”,\“userId \”:2,\“orgId \”:2,\“parentComputerId \”:null, \“lastConnected \”,\“2015 - 03 - 18 - t16:42:55.482凌晨\”,\“osName \”,\“\”,\“赢得osVersion \ 6.2”:\“\”,\“osArch \ ": \ " amd64 \”,\“地址\ ":\ " 192.168.95.128:4242 \”,\“remoteAddress \ ": \ " 172.16.239.1 \”,\“javaVersion \ ": \ " 1.7.0_45 \”,\“modelInfo \”:null, \“时区\”:\“美国芝加哥/ \ \”,\“版本”:1388728800370,\“productVersion \ ": \ " 3.7.0 \”,\“buildVersion \”:null, \“创建日期\": \ " 2015 - 03 - 18 - t16:39:04.241凌晨\”,\“modificationDate \”,\“2015 - 03 - 24 - t09:39:21.135凌晨\”,\“loginDate \”,\“2015 - 03 - 18 - t16:39:07.570凌晨\”,\“服务\ ":\ " Code42 \”},{\ \“computerId \”:12日“名字\”:\“WIN-FQNN6BGK47K \”,\“guid \”,\“680201360538886016 \”,\“\”,\“电脑\”,\“\”,\“积极\”,\“活跃\”:真的,\“屏蔽\”:假的,\“alertState \”:0,\“alertStates \”,\“好的\”,\“userId \”:2,\“orgId \”:2,\“parentComputerId \”:null, \“lastConnected \”,\“2015 - 03 - 12 - t17:17:23.909凌晨\”,\“osName \”,\“赢\”,\“osVersion \”:\“6.2.9200.0 \”,\“osArch \”:null, \“地址\”:\“192.168.95.128:4252 \”,\“remoteAddress \”,\“172.16.239.1 \”,\“javaVersion \”:null, \“modelInfo \”:null, \“时区\”:null, \“版本\”:1413349200416,\“productVersion \”,\“3.7.0 \”,\“buildVersion \”:31日\“创建日期\”,\“2015 - 03 - 12 - t11:53:40.861凌晨\”,\“modificationDate \”,\“2015 - 03 - 12 - t17:17:23.909凌晨\”,\“loginDate \”,\“2015 - 03 - 12 - t16:23:12.272凌晨\”,\“服务\”,\“Code42 \”},{\“computerId \”:10,\“\”,\“WIN-FQNN6BGK47K \”,\“guid \”,\“680190841811656576 \”,\“\”: \“电脑\”,\“\”,\“积极\”,\“活跃\”:真的,\“屏蔽\”:假的,\“alertState \”:0,\“alertStates \”,\“好的\”,\“userId \”:2,\“orgId \”:2,\“parentComputerId \”:null, \“lastConnected \”,\“2015 - 03 - 13 - t13:15:49.352凌晨\”,\“osName \”,\“赢\”,\“osVersion \”,\“6.2.9200.0 \”,\“osArch \”:null, \“地址\”:\“192.168.95.128:4252 \”,\“remoteAddress \”,\“172.16.239.1 \”,\“javaVersion \”:null, \“modelInfo \”:null, \“时区\”:null, \“版本\”:1413349200416,\“productVersion \”,\“3.7.0 \”,\“buildVersion \”:null,创建日期\ \”": \ " 2015 - 03 - 12 - t11:51:13.871凌晨\”,\“modificationDate \”,\“2015 - 03 - 13 - t13:15:49.352凌晨\”,\“loginDate \”,\“2015 - 03 - 12 - t11:51:13.867凌晨\”,\“服务\”,\“Code42 \ "}]}} " = # < HTTP URI::: 0 x0000000265d568 URL: https://console.us.code42.com/api/v1/Computer > @request = # <法拉第:RequestOptions(空的)> @request_headers ={“用户代理”= >“法拉第v0.9.1”、“授权”= >“基本YWRtaW46YWRtaW4 = "} @ssl = # <法拉第:SSLOptions(空的)> @response_headers ={“cache - control”= >“不是商店”、“杂注”= >“no - cache”,"content-location"=>"https://console.us.code42.com/api/v1/Computer", "content-type"=>"application/json;charset=UTF-8", "connection"=>"close", "server"=>"Jetty(7.6.15.v20140411)”}@status = 200 > >