Merhaba arkadaşlar bu makalemizde bu makalemizde local ve
external ip adreslerimizin ne olduğunu bir örnekle göreceğiz.
Şekil 1
WebForm1.aspx.cs
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace get_ip_address_of_server
{
public partial class WebForm1 :
System.Web.UI.Page
{
protected void Page_Load(object sender,
EventArgs e)
{
}
protected void
btnGetIp_Click(object sender, EventArgs e)
{
GetLocalIPAddress();
GetExternalIPAddress();
}
public string
GetLocalIPAddress()
{
string strHostName =
System.Net.Dns.GetHostName();
IPHostEntry
ipHostInfo = System.Net.Dns.Resolve(System.Net.Dns.GetHostName());
IPAddress
ipAddress = ipHostInfo.AddressList[0];
Label3.Text =
ipAddress.ToString();
return
ipAddress.ToString();
}
public string
GetExternalIPAddress()
{
String address =
"";
WebRequest
request = WebRequest.Create("http://checkip.dyndns.org/");
using (WebResponse
response = request.GetResponse())
using (StreamReader
stream = new StreamReader(response.GetResponseStream()))
{
address =
stream.ReadToEnd();
}
Label4.Text =
address.ToString();
return address;
}
}
}
WebForm1.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="get_users_ip_address.WebForm1" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<p style="font-size:xx-large"><b>Your IP
Address (Ip Adresiniz ) : </b></p>
<asp:Label ID="lblIP" runat="server" Font-Bold="True" Font-Names="Arial" Font-Size="XX-Large" ForeColor="#0099FF" Text="Label"></asp:Label>
</div>
</form>
</body>
</html>
Bir
makalenin daha sonuna geldik. Bir sonraki makalede görüşmek üzere. Bahadır
ŞAHİN
0 comments:
Yorum Gönder