Skip to content

Instantly share code, notes, and snippets.

@anomal3
Created January 24, 2025 13:01
Show Gist options
  • Save anomal3/02484b1b2bbd74921d211354d03f7301 to your computer and use it in GitHub Desktop.
Save anomal3/02484b1b2bbd74921d211354d03f7301 to your computer and use it in GitHub Desktop.
HuaweiE3372 Device info (Brovi - E3372-325)
using System.IO.Ports;
using System.Text;
using System.Xml;
class Program
{
static async Task Main()
{
try
{
var e3372 = new HuaweiE3372();
await e3372.FetchAndPrintAllApisAsync();
}
catch (Exception ex)
{
Console.WriteLine($"Ошибка: {ex.Message}");
}
}
class HuaweiE3372
{
private readonly string baseUrl;
private readonly HttpClient httpClient;
private static readonly string[] XmlApis = new[]
{
"/api/device/information",
"/api/device/signal",
"/api/monitoring/status",
"/api/monitoring/traffic-statistics",
"/api/dialup/connection",
"/api/global/module-switch",
"/api/net/current-plmn",
"/api/net/net-mode",
};
public HuaweiE3372(string host = "192.168.8.1")
{
baseUrl = $"http://{host}";
httpClient = new HttpClient
{
BaseAddress = new Uri(baseUrl)
};
// Получение cookie сессии
var cookieUrl = "/html/index.html";
var response = httpClient.GetAsync(cookieUrl).Result;
if (!response.IsSuccessStatusCode)
{
throw new Exception("Не удалось получить cookie сессии.");
}
}
public async Task<Dictionary<string, string>> GetAsync(string path)
{
var response = await httpClient.GetAsync(path);
response.EnsureSuccessStatusCode();
var xmlContent = await response.Content.ReadAsStringAsync();
return ParseXmlResponse(xmlContent);
}
private static Dictionary<string, string> ParseXmlResponse(string xmlContent)
{
var result = new Dictionary<string, string>();
var xmlDocument = new XmlDocument();
xmlDocument.LoadXml(xmlContent);
var responseNode = xmlDocument.SelectSingleNode("response");
if (responseNode == null)
throw new Exception("Ответ не содержит узла 'response'.");
foreach (XmlNode childNode in responseNode.ChildNodes)
{
result[childNode.Name] = childNode.InnerText;
}
return result;
}
public async Task FetchAndPrintAllApisAsync()
{
foreach (var api in XmlApis)
{
Console.WriteLine($"Запрос к API: {api}");
var data = await GetAsync(api);
foreach (var kvp in data)
{
Console.WriteLine($"{kvp.Key}: {kvp.Value}");
}
Console.WriteLine();
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment