사용자가 웹 사이트를 가져와 사용자가 입력 한 웹 사이트의 IP 주소를 얻으려고합니다. 사용자가 모든 웹 사이트를 입력 할 수있는 텍스트 상자가 있습니다. 사용자가 "www.Google.com"을 입력하면 그 텍스트는 System.Net.Dns.GetHostAddresses(Convert.ToString(urlTextbox));
이됩니다. 그러나 이것을 실행하고 프로그램을 테스트하면 소켓 처리되지 않은 오류가 발생합니다. 해당 호스트가 없습니다. 이 문제를 해결하려면 어떻게해야합니까?URL에서 IP 주소를 가져 오는 중 소켓 오류가 발생했습니다.
이 내가 원하는 것입니다 :
이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;
using System.Net;
namespace Challenger
{
public partial class Form1 : Form
{
int ipWidth;
string x;
public Form1()
{
InitializeComponent();
urlTextbox.Text ="www.";
ipLabelText();
}
private void button2_Click(object sender, EventArgs e)
{
System.Net.IPAddress[] addresses =
System.Net.Dns.GetHostAddresses(Convert.ToString(urlTextbox));
string ipTextLength = Convert.ToString(addresses[0]);
//Stores the amount of digits
ipWidth = ipTextLength.Length;
//Puts ip into a string-> Label for Display
label2.Text = Convert.ToString(addresses[0]);
label2.Location = new Point(80, 20);
}
public void ipLabelText()
{
label2.Parent = panel1;
label2.BackColor = Color.Transparent;
label2.ForeColor = Color.White;
}
}
}
//Porting LOIC Android Application in C#
해당 코드는'GetHostByAddress'를 사용하지 않습니다. 그리고 OP가 단지 IP 주소 만 필요로한다면'GetHostAddresses' 메쏘드 (사용되는 _is)는 적어도 유효한 호스트 이름으로 호출 될 때 잘 동작합니다. :) –