Showing posts with label .Net. Show all posts
Showing posts with label .Net. Show all posts

Monday, July 8, 2019

Validating SSL Certificate in .Net C#




.Net console application to get the site certificate to validate and show cert info.


using System;
using System.Net;
using System.Net.Security;
using System.Security.Cryptography.X509Certificates;
using System.Security;

namespace CertValidate

{
    class Program
    {
       
                
        static void Main(string[] args)
        {

            while (true) {


                Console.WriteLine("Enter Full URL");

               CheckSite(Console.ReadLine());
            }
        }


        public static void CheckSite(string URL) {


              

            HttpWebRequest request = WebRequest.CreateHttp(URL);
            request.ServerCertificateValidationCallback += ServerCertificateValidationCallback;
            using (HttpWebResponse response = (HttpWebResponse)request.GetResponse()) { }
            Console.WriteLine("End.");
             
        }

        private static bool ServerCertificateValidationCallback(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)

        {

            if (sslPolicyErrors == SslPolicyErrors.None)

            {
                Console.WriteLine("Certificate OK");
                Console.WriteLine(certificate.ToString());
                return true;
            }
            else
            {
                Console.WriteLine("Certificate ERROR");
                return false;
            }
        }

    }


}


Monday, August 15, 2011

For all Gadgets+.Net Micro fans .Net Gadgeteer is now available...
http://www.ghielectronics.com/catalog/product/297


Description
FEZ Spider Starter Kit is the first commercially available .NET Gadgeteer-compatible kit. it includes everything necessary for educators, hobbyists and even professionals. Embedded development is fast & easy (FEZ) thanks to .NET Micro Framework, .NET Gadgeteer and the numerous GHI value added features such as WiFi and USB Host.
The kit includes:
FEZ Spider Mainboard is a .NET Gadgeteer-compatible mainboard based on GHI Electronics' EMX module. This makes FEZ Spider Mainboard the most feature-full .NET Gadgeteer compatible device in the market. It contains all of .NET Micro Framework core features and adds many exclusive features, such as USB host, WiFi and RLP (loading native code). All these features combine to provide a rapid prototyping platform.

Key Features:
  • 14 .NET Gadgeteer compatible sockets
  • Configurable on-board LED
  • Configuration switches.
  • Based on GHI Electronics EMX module
    • 72MHz 32-bit ARM7 processor
    • 4.5 MB Flash
    • 16 MB RAM
    • LCD controller
    • Full TCP/IP Stack with SSL, HTTP, TCP, UDP, DHCP
    • Ethernet, WiFi driver and PPP ( GPRS/ 3G modems) and DPWS
    • USB host
    • USB Device with specialized libraries to emulate devices like thumb-drive, virtual COM (CDC), mouse, keyboard
    • 76 GPIO Pin
    • 2 SPI (8/16bit)
    • I2C
    • 4 UART
    • 2 CAN Channels
    • 7 10-bit Analog Inputs
    • 10-bit Analog Output (capable of WAV audio playback)
    • 4-bit SD/MMC Memory card interface
    • 6 PWM
    • OneWire interface (available on any IO)
    • Built-in Real Time Clock (RTC) with the suitable crystal
    • Processor register access
    • OutputCompare for generating waveforms with high accuracy
    • RLP allowing users to load native code (C/Assembly) for real-time requirements
    • Extended double-precision math class
    • FAT File System
    • Cryptography (AES and XTEA)
    • Low power and hibernate support
    • In-field update (from SD, network or other)
  • Dimensions: W 2.25" x L 2.05" x H 0.5"
Power
  • Supply voltages are regulated 3.3Volt and 5.0Volt DC.
  • Low power and hibernate modes
  • Active power consumption 160 mA
  • Idle power consumption 120 mA
  • Hibernate power consumption 40 mA
Enviromental:
  • Operating temperature: -20 to 65°C
  • RoHS compliant /Lead-free compliant
Most EMX software features are GHI exclusive, see software documentation for details.
For more information about .NET Gadgeteer visit:
http://www.netmf.com/gadgeteer/



Thursday, August 26, 2010

C# FAQs Series: How To Detect All Drives Connected?


àIn C# FAQs Series: We discuss most frequent questions asked on C# forums.
If you want to know about how many drives are connected to your computer. It’s very easy to detect using C#. Following is simple code…
Source Code:
using System;
using System.IO;
class MyProgram
{
public static void Main()
{
DriveInfo[] allDrives = DriveInfo.GetDrives();
foreach (DriveInfo d in allDrives)
{
Console.WriteLine("Drive {0}", d.Name);
Console.WriteLine(" File type: {0}", d.DriveType);
if (d.IsReady == true)
{
Console.WriteLine(" Volume label: {0}", d.VolumeLabel);
Console.WriteLine(" File system: {0}", d.DriveFormat);
Console.WriteLine(
" Available space to current user:{0, 15} bytes",
d.AvailableFreeSpace);
Console.WriteLine(
" Total available space: {0, 15} bytes",
d.TotalFreeSpace);
Console.WriteLine(
" Total size of drive: {0, 15} bytes ",
d.TotalSize);
}
}
}
}
Out-Put:
/*
This code produces output similar to the following:
Drive A:\
File type: Removable
Drive C:\
File type: Fixed
Volume label:
File system: FAT32
Available space to current user: 4770430976 bytes
Total available space: 4770430976 bytes
Total size of drive: 10731683840 bytes
Drive D:\
File type: Fixed
Volume label:
File system: NTFS
Available space to current user: 15114977280 bytes
Total available space: 15114977280 bytes
Total size of drive: 25958948864 bytes
Drive E:\
File type: CDRom
The actual output of this code will vary based on machine and the permissions
granted to the user executing it.
*/

Monday, August 16, 2010

C# FAQs Series: How Use FTP Using C#


àIn C# FAQs Series: We discuss most frequent questions asked on C# forums.
As a C# developer you may often have to use FTP. Following is simple program which will demonstrate how to FTP using C#.
using System;
using System.IO;
using System.Net;
using System.Text;
namespace Examples.System.Net
{
public class WebRequestGetExample
{
public static void Main ()
{
// Geting the object used to communicate with the server.
FtpWebRequest FWRrequest = (FtpWebRequest)WebRequest.Create( "ftp://www.mrmubi.com/mytest.htm");
request.Method = WebRequestMethods.Ftp.UploadFile;
// Set network credentials.
FWRrequest.Credentials = new NetworkCredential ("user","password");
// Copy the contents of the file to the request stream.
StreamReader sourceStream = new StreamReader("myfile.txt");
byte [] fileContents = Encoding.UTF8.GetBytes(sourceStream.ReadToEnd());
sourceStream.Close();
FWRrequest.ContentLength = fileContents.Length;
Stream requestStream = FWRrequest.GetRequestStream();
requestStream.Write(fileContents, 0, fileContents.Length);
requestStream.Close();
FtpWebResponse response = (FtpWebResponse)request.GetResponse();
Console.WriteLine("File upload complete , status {0}", response.StatusDescription);
response.Close();
}
}
}
}
How to download file using FTP in C#...
public static bool DisplayFileFromServer(Uri serverUri)
{
    // The serverUri parameter should start with the ftp:// scheme.
    if (serverUri.Scheme != Uri.UriSchemeFtp)
    {
        return false;
    }
    // Geting the object used to communicate with the server.
    WebClient WCrequest = new WebClient();
 
    // Credentials
    WCrequest.Credentials = new NetworkCredential ("user","password");
    try 
    {
        byte [] newFileData = WCrequest.DownloadData (serverUri.ToString());
        string fileString = System.Text.Encoding.UTF8.GetString(newFileData);
        Console.WriteLine(fileString);
    }
    catch (WebException e)
    {
        Console.WriteLine(e.ToString());
    }
    return true;
}
How to delete file using FTP in C#...
public static bool DeleteFileOnServer(Uri serverUri)
{
    // The serverUri parameter should use the ftp:// scheme.
    // It contains the name of the server file that is to be deleted.
    // Example: ftp://contoso.com/someFile.txt.
    // 
 
    if (serverUri.Scheme != Uri.UriSchemeFtp)
    {
        return false;
    }
    // Get the object used to communicate with the server.
    FtpWebRequest FWRrequest = (FtpWebRequest)WebRequest.Create(serverUri);
    FWRrequest.Method = WebRequestMethods.Ftp.DeleteFile;
 
    FtpWebResponse FWRresponse = (FtpWebResponse) FWRrequest.GetResponse();
    Console.WriteLine("File delete status: {0}",FWRresponse.StatusDescription);  
    FWRresponse.Close();
    return true;
}
You see how easy is it to play with your FTP account in C#.