Search My Warehouse

2009-12-31

Fetch IP address connected in LAN windows c#

IP addresses of Client machines connected in LAN


private void but_fetchIPAddr_Click(object sender, EventArgs e)
{
but_fetchIPAddr.Enabled = false;
DirectoryEntry ParentEntry = new DirectoryEntry();
try
{
ParentEntry.Path = "WinNT:";
foreach (DirectoryEntry childEntry in ParentEntry.Children)
{
TreeNode newNode = new TreeNode(childEntry.Name);
switch (childEntry.SchemaClassName)
{
case "Domain":
TreeNode ParentDomain = new TreeNode(childEntry.Name);
treeView1.Nodes.AddRange(new TreeNode[] { ParentDomain });
DirectoryEntry SubParentEntry = new DirectoryEntry();
SubParentEntry.Path = "WinNT://" + childEntry.Name;
foreach (DirectoryEntry SubChildEntry in SubParentEntry.Children)
{
TreeNode newNode1 = new TreeNode(SubChildEntry.Name);
switch (SubChildEntry.SchemaClassName)
{
case "Computer":
ParentDomain.Nodes.Add(newNode1);
break;
}
}
break;
}
}
}
finally
{
ParentEntry = null;
treeView1.Visible = true;

}
}

private void treeView1_AfterSelect(object sender, TreeViewEventArgs e)
{
txtServer.Text = GetIPAddress(treeView1.SelectedNode.Text);
}


public string GetIPAddress(string CompName)
{

System.Net.IPAddress oAddr = default(System.Net.IPAddress);
string sAddr = null;
try
{
{
oAddr = new System.Net.IPAddress(System.Net.Dns.GetHostByName(CompName).AddressList[0].Address);
sAddr = oAddr.ToString();
}
}
catch (System.Exception Excep)
{
MessageBox.Show("Select the Name of a Client not a Group.");
}
finally
{
}
return sAddr;
}

send mail in asp.net c#

web.config










aspx.cs

string ToMail, FromMail, MailBody, host, portNo, password;

page load:

FromMail = ConfigurationManager.AppSettings["mailFrom"];
password = ConfigurationManager.AppSettings["password"];
host = ConfigurationManager.AppSettings["host"];
portNo = ConfigurationManager.AppSettings["port"];
ToMail = Request.QueryString[1].ToString();
MailBody="test mail";

button click


MailMessage mailMessage = new MailMessage(FromMail, ToMail, "Hello ! " + ToMail + ", Mr/Mrs" + ToMail + "Has Replied you", MailBody);
mailMessage.IsBodyHtml = true;
SmtpClient smtpClient = new SmtpClient();
smtpClient.UseDefaultCredentials = false;
NetworkCredential networkCredential = new NetworkCredential(FromMail, password);
smtpClient.Host = host;
mailMessage.Priority = MailPriority.High;
if (!string.IsNullOrEmpty(portNo))
{
smtpClient.Port = Convert.ToInt32(portNo);
smtpClient.EnableSsl = true;
}
smtpClient.Credentials = networkCredential;
smtpClient.Send(mailMessage);


------------------------------------------------------------------------------------------



using System.Net;
using System.Net.Mail;
using System.Web.Configuration;

Method I
-----------

System.Configuration.Configuration config = WebConfigurationManager.OpenWebConfiguration(HttpContext.Current.Request.ApplicationPath);
System.Net.Configuration.MailSettingsSectionGroup settings = (System.Net.Configuration.MailSettingsSectionGroup)config.GetSectionGroup("system.net/mailSettings");
System.Net.NetworkCredential credential = new System.Net.NetworkCredential(settings.Smtp.Network.UserName, settings.Smtp.Network.Password);

int i = 0;
//Create the SMTP Client
SmtpClient client = new SmtpClient();
client.Host = settings.Smtp.Network.Host;
client.Credentials = credential;
HttpResponse response = HttpContext.Current.Response;
MailMessage email = new MailMessage();

email.IsBodyHtml = true;
email.From = new MailAddress(FromMail);
email.To.Add("ranjith@isolve.co.in");
// email.To.Add(ToMail);

//email.To.Add(strToEmail)
email.Subject = SubjecT;
email.IsBodyHtml = true;
email.Body = MailBody;
email.DeliveryNotificationOptions = DeliveryNotificationOptions.OnFailure;

try
{
client.Send(email);
}
catch (Exception exc)
{
response.Write("Send failure: " + exc.ToString());
}


WEB.CONFIG
============


<appSettings>
<add key="SenderUsername" value="xx@gmail.com"/>
<add key="SenderPassword" value="xx"/>
<add key="HostIP" value="***.***.***.***"/>

</appSettings>





============================================================

Method II
-------------

public void SendMail(string FrmMail, string ToMail, string MailBody, string SubjecT)
{
System.Configuration.Configuration config = WebConfigurationManager.OpenWebConfiguration(HttpContext.Current.Request.ApplicationPath);
System.Net.Configuration.MailSettingsSectionGroup settings = (System.Net.Configuration.MailSettingsSectionGroup)config.GetSectionGroup("system.net/mailSettings");
System.Net.NetworkCredential credential = new System.Net.NetworkCredential(settings.Smtp.Network.UserName, settings.Smtp.Network.Password);

int i = 0;
//Create the SMTP Client
SmtpClient client = new SmtpClient();
client.Host = settings.Smtp.Network.Host;
client.Credentials = credential;
HttpResponse response = HttpContext.Current.Response;
MailMessage email = new MailMessage();



email.IsBodyHtml = true;
email.From = new MailAddress(FrmMail);
email.To.Add(ToMail);
//email.To.Add(ToMail);

//email.To.Add(strToEmail)
email.Subject = SubjecT;
email.IsBodyHtml = true;
email.Body = MailBody;
email.DeliveryNotificationOptions = DeliveryNotificationOptions.OnFailure;

try
{
client.Send(email);

}
catch (Exception exc)
{
response.Write("Send failure: " + exc.ToString());

}
}


*FIREWALL SHOULD BE OFF

-------------------------------------------------------------------

Feed