Hello, I have multiple networks with a changing amount of devices on each. What I'm trying to do is have those devices report their ip address to a website where I can enter in their mac address and determine which ip address it's coming from so that I can control said device with my program. Basically I'm trying to figure out if I can do this from C#(that is, broadcast each device to the website). From there I would like to be able to use code to connect and control devices similar to:
HttpWebRequest WebReq = (HttpWebRequest)WebRequest.Create("http://website/ip.html");
WebReq.Method = "POST";
//We use form contentType, for the postvars.
WebReq.ContentType = "application/x-www-form-urlencoded";
//stream for postvars
Stream PostData = WebReq.GetRequestStream();
HttpWebResponse WebResp = (HttpWebResponse)WebReq.GetResponse();
Stream Answer = WebResp.GetResponseStream();
StreamReader _Answer = new StreamReader(Answer);
string parsed = _Answer.ReadToEnd();
//used to get ip and port dynamically
string[] parts = parsed.Split(':');
if (parts.Length != 2)
{
//throw exception
}
string host = parts[0];
string port = parts[1];
string html;
// obtain some arbitrary html....
using (var client = new WebClient())
{
html = client.DownloadString("ip.html");
}
// use the html agility pack: http://www.codeplex.com/htmlagilitypack
HtmlDocument doc = new HtmlDocument();
doc.LoadHtml(html);
StringBuilder sb = new StringBuilder();
foreach (HtmlTextNode node in doc.DocumentNode.SelectNodes("//text()"))
{
sb.AppendLine(node.Text);
}
string final = sb.ToString();
TcpClient ourMagicClient = new TcpClient();
//entering the mac address will direct it to the device
Console.WriteLine(sb.ToString());
Console.ReadKey();
ourMagicClient.Connect(host,Convert.ToInt32(port));
NetworkStream ourStream = ourMagicClient.GetStream();