nikhil joshi
C#
Crazy idea…
Jun 11th
I am getting bored while working on daily ‘shit’. nothing really drives me. In office it work i do for last 2 year; so I know how to find solutions for problems. It is not very challenging coding part. So I got and crazy idea.
I will implement RFCs one by one in C# code.
I am choosing C# as this is easy to use and I want to do some heavy coding in C#. Lets see how this work out.
I am staring on http://www.rfc-editor.org/rfcxx00.html form top to bottom.
Get all database names form MSSQL 2005
Apr 9th
String conxString = “Data Source=” + server + “; Integrated Security=True;”;
using (System.Data.SqlClient.SqlConnection sqlConx = new System.Data.SqlClient.SqlConnection(conxString)) {
sqlConx.Open();
DataTable tblDatabases = sqlConx.GetSchema(“Databases”);
sqlConx.Close();
foreach (DataRow row in tblDatabases.Rows) {
Console.WriteLine(“Database: ” + row["database_name"]);
}
}
Check given IP address is valid for given machine
Mar 24th
Given code useDns.GetHostAddresses(). This function resolves machine host name to IP address. And if IP address is given it check for IP address and if valid returns given IP address.
-
string machineName = "localhost";
-
string checkIP = "127.0.0.1";
-
-
IPAddress[] ipsMachineName = null;
-
IPAddress[] ipsCheckIP = null;
-
//fetch IPs for machine
-
try {
-
ipsMachineName = Dns.GetHostAddresses(machineName);
-
}
-
catch (Exception expMachine) {
-
Console.WriteLine(string.Format("Error while retriving IP address of machine ‘{0}’ : {1} ", machineName, expMachine.Message));
-
return;
-
}
-
//Check IP addrss
-
try {
-
ipsCheckIP = Dns.GetHostAddresses(checkIP);
-
}
-
catch (Exception expIP) {
-
Console.WriteLine(string.Format("Invalid IP address: {0}", expIP.Message));
-
return;
-
}
-
//check ip address.
-
bool validIPAddress = false;
-
foreach (IPAddress machineIP in ipsMachineName) {
-
foreach (IPAddress cIP in ipsCheckIP) {
-
if (string.Compare(machineIP.ToString(), cIP.ToString(), true) == 0) {
-
validIPAddress = true;
-
break;
-
}
-
}
-
if (validIPAddress) {
-
break;
-
}
-
}
-
if (validIPAddress) {
-
Console.WriteLine("Valid IP address");
-
}
-
else {
-
Console.WriteLine("Invalid IP address");
-
}
Recent Comments