132 lines
5.5 KiB
C#
132 lines
5.5 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Collections;
|
|
using System.Net.NetworkInformation;
|
|
using System.Net;
|
|
using MotoTRBO_GW;
|
|
using SafeMobileLib;
|
|
|
|
namespace MotoTrbo_GW
|
|
{
|
|
class RadioStuff
|
|
{
|
|
public static List<GatewayID_IP> getAllRadiosIPs()
|
|
{
|
|
List<GatewayID_IP> ipList = new List<GatewayID_IP>();
|
|
NetworkInterface[] interfaces = NetworkInterface.GetAllNetworkInterfaces();
|
|
try
|
|
{
|
|
foreach (NetworkInterface n in interfaces)
|
|
{
|
|
//SafeMobileLib.Utils.WriteLine("Descriport name:" + n.Description);
|
|
//old code if (n.Description.Contains("MOTOTRBO"))
|
|
if ((n.Description.ToUpper().Contains("MOTOTRBO"))||(n.Description.ToUpper().Contains("BLUETOOTH")))
|
|
//if (n.Description.ToUpper().Contains("MOTOTRBO"))
|
|
{
|
|
GatewayID_IP radioID_IP = new GatewayID_IP();
|
|
IPInterfaceProperties ipProperties = n.GetIPProperties();
|
|
radioID_IP.ID = (n.GetIPProperties().GetIPv4Properties().Index).ToString();
|
|
radioID_IP.remoteIP = "";
|
|
IPAddressCollection IpCol = ipProperties.DhcpServerAddresses;
|
|
SafeMobileLib.Utils.WriteLine("In mototrbo "+IpCol.Count);
|
|
if (IpCol.Count > 0)
|
|
{
|
|
foreach (IPAddress ip in IpCol)
|
|
{
|
|
SafeMobileLib.Utils.WriteLine("IP's: " + ip.ToString());
|
|
radioID_IP.remoteIP = ip.ToString();
|
|
}
|
|
}
|
|
foreach (UnicastIPAddressInformation addr in ipProperties.UnicastAddresses)
|
|
{
|
|
//SafeMobileLib.Utils.WriteLine("Radio localIP :" + addr.Address);
|
|
if (addr.Address.ToString().StartsWith("192."))
|
|
{
|
|
radioID_IP.localIP = addr.Address.ToString();
|
|
}
|
|
}
|
|
//SafeMobileLib.Utils.WriteLine("Radio RemoteIP:"+radioID_IP.remoteIP);
|
|
if(radioID_IP.remoteIP != "")
|
|
ipList.Add(radioID_IP);
|
|
}
|
|
}
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
SafeMobileLib.Utils.WriteLine("RadioStuff getAllRadiosIPs Exception: " + e.ToString());
|
|
}
|
|
return ipList;
|
|
}
|
|
|
|
public static string GetInterface(string IPstr)
|
|
{
|
|
string strInterface = "";
|
|
try
|
|
{
|
|
string[] arrStr = IPstr.Split('.');
|
|
int lastPartOfIP = Convert.ToInt32(arrStr[3]);
|
|
arrStr[3] = (lastPartOfIP + 1).ToString();
|
|
strInterface = arrStr[0] + "." + arrStr[1] + "." + arrStr[2] + "." + arrStr[3];
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
SafeMobileLib.Utils.WriteLine("Error GEtting interface");
|
|
SafeMobileLib.Utils.WriteLine(ex.ToString());
|
|
}
|
|
return strInterface;
|
|
}
|
|
|
|
public static string GetReverse_Interface(string IPstr)
|
|
{
|
|
string strInterface = "";
|
|
try
|
|
{
|
|
string[] arrStr = IPstr.Split('.');
|
|
int lastPartOfIP = Convert.ToInt32(arrStr[3]);
|
|
arrStr[3] = (lastPartOfIP - 1).ToString();
|
|
strInterface = arrStr[0] + "." + arrStr[1] + "." + arrStr[2] + "." + arrStr[3];
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
SafeMobileLib.Utils.WriteLine("Error GEtting interface");
|
|
SafeMobileLib.Utils.WriteLine(ex.ToString());
|
|
}
|
|
return strInterface;
|
|
}
|
|
|
|
public static string GetInterfaceID(string ip)
|
|
{
|
|
string id = "";
|
|
DateTime time = DateTime.Now;
|
|
NetworkInterface[] interfaces = NetworkInterface.GetAllNetworkInterfaces();
|
|
SafeMobileLib.Utils.WriteLine("GetInterfaceID time to complete:" + (DateTime.Now - time));
|
|
foreach (NetworkInterface n in interfaces)
|
|
{
|
|
//old code if (n.Description.Contains("MOTOTRBO"))
|
|
if ((n.Description.ToUpper().Contains("MOTOTRBO")) || (n.Description.ToUpper().Contains("BLUETOOTH")))
|
|
//if (n.Description.ToUpper().Contains("MOTOTRBO"))
|
|
{
|
|
IPInterfaceProperties ipProperties = n.GetIPProperties();
|
|
string temp_id = (n.GetIPProperties().GetIPv4Properties().Index).ToString();
|
|
SafeMobileLib.Utils.WriteLine("Desc " + n.Description + " ID:" + temp_id);
|
|
foreach (UnicastIPAddressInformation addr in ipProperties.UnicastAddresses)
|
|
{
|
|
//if (addr.Address.ToString().StartsWith("192."))
|
|
//{
|
|
string trboRemoteIP = GetInterface(ip);
|
|
if (trboRemoteIP == addr.Address.ToString())
|
|
{
|
|
id = temp_id;
|
|
}
|
|
//}
|
|
}
|
|
}
|
|
}
|
|
|
|
return id;
|
|
}
|
|
}
|
|
}
|