26 Şubat 2015 Perşembe

C# İle İnternet Bağlantısı Kontrol Etme















using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;



namespace İnternet_bağlantısı
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        public static bool TcpSocketTest()
        {
            try
            {
                System.Net.Sockets.TcpClient client =
                    new System.Net.Sockets.TcpClient("www.google.com", 80);
                client.Close();
                return true;
            }
            catch (System.Exception ex)
            {
                return false;
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (TcpSocketTest() == true)
            {
                label1.Text="İnternet Bağlantısı Var";
                label1.ForeColor = Color.Green;
            }
            else
            {
                label1.Text="İnternet Bağlantısı Yok";
                label1.ForeColor = Color.Red;
            }
        }
    }
}

Paylaş:

0 yorum:

Yorum Gönder

Popüler

Son

Kategoriler