Search code examples
c#.netpingteamviewer

Ping Teamviewer Id's


Hi guys i have Teamviewer installed and would like to be able to ping Teamviewer ID's and get a response of the status of that PC.

try
{
    string accessToken = "xxxxxxxxxxxxxxxxxxxx";
    string Version = "v1";
    string tvApiUrl = "https://webapi.teamviewer.com";
    string address = tvApiUrl + "/api/" + Version + "/various commands from API";
    HttpWebRequest request = WebRequest.Create(address) as HttpWebRequest;
    request.Headers.Set("Authorization", "Bearer " + accessToken);
    request.Method = "GET";
    WebResponse response = request.GetResponse();
    return response;
}
catch (Exception ex) 
{
    MessageBox.Show("Failed to get request with error: " + ex.Message);
    return null;
}

this wont work because I haven't found anything related to the remote list of computers i have in Teamviewer. I want a way to check if the PC's in my Teamviewer list have internet programmatically. Thanks in advance


Solution

  • This can be achieved using the TeamViewer API.

    Have a look at the documentation under "3.10 Devices":

    GET /api/v1/devices (list all devices from the computers & contacts list)

    • Parameters

      • online_state (optional) – Return only devices with the given online_state.
      • groupid (optional) – Return only contacts that are in the specified group.
    • Return values

      • device_id – The ID that is unique for this entry of the computers & contacts list. Values are always prefixed with a d.
      • remotecontrol_id – The ID that is unique to this device and can be used to start a remote control session.
      • groupid – The ID of the group that this device is a member of.
      • alias – The alias that the current user has given to this device.
      • description – The description that the current user has entered for this device.
      • online_state – The current online state of the device. Possible values are: online, offline.
    • Authentication

      • User access token. Scope: ContactList.Read.
    • Description
      • Returns a list of devices in the user’s computers & contacts list.
    • Example

    Request

    GET /api/v1/devices
    

    Response

    HTTP/1.1 200 OK  
       Content-Type: application/json 
     { "devices": [  
          {  
              "remotecontrol_id": "r123456789",  
              "device_id": "d123456789",  
              "alias": "PC",  
              "groupid": "g12345678",  
              "online_state": "Online"  
          },  
          {  
              "remotecontrol_id": "r123456780",  
              "device_id": "d345667567",  
              "alias": "Laptop",  
              "groupid": "g12345678",  
              "online_state": "Offline" 
          },  
          {  
              "remotecontrol_id": "r345678890",  
              "device_id": "d444443226",  
              "alias": "Office",  
              "groupid": "g12345678",  
              "online_state": "Offline" 
          }  
       ] 
    }