本文整理汇总了C#中System.Net.IPAddress类的典型用法代码示例。如果您正苦于以下问题:C# IPAddress类的具体用法?C# IPAddress怎么用?C# IPAddress使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
IPAddress类属于System.Net命名空间,在下文中一共展示了IPAddress类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: button1_Click
private void button1_Click(object sender, EventArgs e)
{
System.Diagnostics.Stopwatch watch = new System.Diagnostics.Stopwatch();
var ControllerIPAddress = new IPAddress(new byte[] { 192, 168, 0, 2 });
var ControllerPort = 40001;
var ControllerEndPoint = new IPEndPoint(ControllerIPAddress, ControllerPort);
_client = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
var header = "@";
var command = "00C";
var checksum = "E3";
var end = "\r\n";
var data = header + command + checksum + end;
byte[] bytes = new byte[1024];
//Start Connect
_connectDone.Reset();
watch.Start();
_client.BeginConnect(ControllerIPAddress, ControllerPort, new AsyncCallback(ConnectCallback), _client);
//wait 2s
_connectDone.WaitOne(2000, false);
var text = (_client.Connected) ? "ok" : "ng";
richTextBox1.AppendText(text + "\r\n");
watch.Stop();
richTextBox1.AppendText("Consumer time: " + watch.ElapsedMilliseconds + "\r\n");
}
示例2: IPv4Destination
public IPv4Destination(IPAddress ip, uint port, bool isOpenExternally)
: base(ip, port, isOpenExternally)
{
if (ip.AddressFamily != AddressFamily.InterNetwork) {
throw new ArgumentException(String.Format("ip must be IPv4 (was {0})", ip));
}
}
示例3: HandleRData
private void HandleRData(NetBinaryReader nbr)
{
long startPos = nbr.BaseStream.Position;
switch (Type)
{
case (QType.A):
case (QType.AAAA):
recordValue = new IPAddress(nbr.ReadBytes(ByteCount));
break;
/*
case (QType.NS):
case (QType.CNAME):
recordValue = nbr.ReadLblOrPntString();
ReadPadOctets(nbr, startPos);
break;
case (QType.SOA):
recordValue = new SOA(nbr);
ReadPadOctets(nbr, startPos);
break;
*/
default:
recordValue = nbr.ReadBytes(ByteCount);
break;
}
}
示例4: IPNetwork
public IPNetwork(IPAddress address, int cidr)
{
if (address == null)
{
throw new ArgumentNullException("address");
}
int addressBitLength;
if (address.AddressFamily == AddressFamily.InterNetwork)
{
addressBitLength = 32;
}
else if (address.AddressFamily == AddressFamily.InterNetworkV6)
{
addressBitLength = 128;
}
else
{
throw new FormatException("Unsupported network address family.");
}
if (cidr < 0 || cidr > addressBitLength)
{
throw new ArgumentOutOfRangeException("cidr");
}
_NetworkAddress = address;
_CIDR = cidr;
_Mask = GenerateMask(cidr, addressBitLength);
}
示例5: StartWebDAV
/// <summary>
/// Start the WebDAV interface using the given ip address, port and HTTPSecurity parameters.
/// </summary>
/// <param name="myIPAddress">The IPAddress for binding the interface at</param>
/// <param name="myPort">The port for binding the interface at</param>
/// <param name="myHttpWebSecurity">A HTTPSecurity class for checking security parameters like user credentials</param>
public static Exceptional<HTTPServer<GraphDSWebDAV_Service>> StartWebDAV(this AGraphDSSharp myAGraphDSSharp, IPAddress myIPAddress, UInt16 myPort, HTTPSecurity myHttpWebSecurity = null)
{
try
{
// Initialize WebDAV service
var _HttpWebServer = new HTTPServer<GraphDSWebDAV_Service>(
myIPAddress,
myPort,
new GraphDSWebDAV_Service(myAGraphDSSharp),
myAutoStart: true)
{
HTTPSecurity = myHttpWebSecurity,
};
// Register the WebDAV service within the list of services
// to stop before shutting down the GraphDSSharp instance
myAGraphDSSharp.ShutdownEvent += new GraphDSSharp.ShutdownEventHandler((o, e) =>
{
_HttpWebServer.StopAndWait();
});
return new Exceptional<HTTPServer<GraphDSWebDAV_Service>>(_HttpWebServer);
}
catch (Exception e)
{
return new Exceptional<HTTPServer<GraphDSWebDAV_Service>>(new GeneralError(e.Message, new System.Diagnostics.StackTrace(e)));
}
}
示例6: Start
public void Start(string address, int port, string path)
{
IPAddress ipaddr = new IPAddress(address.Split('.').Select(a => (byte)a.to_i()).ToArray());
WebSocketServer wss = new WebSocketServer(ipaddr, port, this);
wss.AddWebSocketService<ServerReceiver>(path);
wss.Start();
}
示例7: IsLocalIP
/// <summary>
/// Checks if a ipv4 address is a local network address / zeroconf
/// </summary>
/// <param name="ip"></param>
/// <returns></returns>
public static bool IsLocalIP(IPAddress ip)
{
if (ip.AddressFamily == AddressFamily.InterNetwork)
{
byte[] ipBytes = ip.GetAddressBytes();
// 10.0.0.0 bis 10.255.255.255 :: 10.0.0.0/8 (1 Class C)
if (ipBytes[0] == 10)
{
return true;
}
// 172.16.0.0 bis 172.31.255.255 :: 172.16.0.0/12 (16 Class B)
if ((ipBytes[0] == 172) && (ipBytes[1] > 15) && (ipBytes[1] < 32))
{
return true;
}
// 192.168.0.0 bis 192.168.255.255 :: 192.168/16 (256 Class C)
if ((ipBytes[0] == 192) && (ipBytes[1] == 168))
{
return true;
}
// 169.254.0.0 bis 169.254.255.255 :: 169.254.0.0/16 (Zeroconf)
if ((ipBytes[0] == 169) && (ipBytes[1] == 255))
{
return true;
}
}
return false;
}
示例8: TryParse
public static bool TryParse(string ip, out IPAddress address) {
// Only handle IPv4
if (ip == null) {
throw new ArgumentNullException("ip");
}
if (ip.Length == 0 || ip == " ") {
address = new IPAddress(0);
return true;
}
string[] parts = ip.Split('.');
if (parts.Length != 4) {
address = null;
return false;
}
uint a = 0;
for (int i = 0; i < 4; i++) {
int val;
if (!int.TryParse(parts[i], out val)) {
address = null;
return false;
}
a |= ((uint)val) << (i << 3);
}
address = new IPAddress((long)a);
return true;
}
示例9: Blacklist
public virtual void Blacklist(IPAddress senderAddress)
{
if (!_blacklist.ContainsKey(senderAddress))
{
_blacklist.Add(senderAddress, true);
}
}
示例10: ClientSocket
public ClientSocket(IPAddress address, int port)
: base(10, LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType))
{
this.Setup(new IPEndPoint(address, port), new ClientMessageProcessor());
Handler = new Handler();
Rpc = new BinarySenderStub(this);
}
示例11: SslServer
public SslServer(X509Certificate2 cert, bool certRequired, SslProtocols enabledProt, bool expectedExcep)
{
certificate = cert;
clientCertificateRequired = certRequired;
enabledSslProtocols = enabledProt;
expectedException = expectedExcep;
if (!certificate.HasPrivateKey)
{
Console.WriteLine("ERROR: The cerfiticate does not have a private key.");
throw new Exception("No Private Key in the certificate file");
}
//Get the IPV4 address on this machine which is all that the MF devices support.
foreach (IPAddress address in Dns.GetHostAddresses(Dns.GetHostName()))
{
if (address.AddressFamily == AddressFamily.InterNetwork)
{
ipAddress = address;
break;
}
}
if (ipAddress == null)
throw new Exception("No IPV4 address found.");
//Console.WriteLine("ipAddress is: " + ipAddress.ToString());
//Console.WriteLine("port is: " + port.ToString());
}
示例12: OpenSocket
partial void OpenSocket(IPAddress connectedHost, uint connectedPort)
{
var ep = new IPEndPoint(connectedHost, (int)connectedPort);
this._socket = new Socket(ep.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
this._socket.Connect(ep);
this._socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.NoDelay, 1);
}
示例13: init
public void init()
{
try
{
Console.WriteLine("Init");
//set up socket
Socket client = new Socket(AddressFamily.InterNetwork,
SocketType.Stream, ProtocolType.Tcp);
//IPHostEntry hostInfo = Dns.Resolve("localhost:8000");
//IPAddress address = hostInfo.AddressList[0];
//IPAddress ipAddress = Dns.GetHostEntry("localhost:8000").AddressList[0];
IPAddress ipAddress = new IPAddress(new byte[] { 128, 61, 105, 215 });
IPEndPoint ep = new IPEndPoint(ipAddress, 8085);
client.BeginConnect(ep, new AsyncCallback(ConnectCallback), client);
connectDone.WaitOne();
//receiveForever(client);
byte[] msg = Encoding.ASCII.GetBytes("This is a test<EOF>");
StateObject state = new StateObject();
state.workSocket = client;
client.BeginReceive(buffer, 0, StateObject.BufferSize, 0,
new AsyncCallback(ReceiveCallback), state);
client.Send(msg);
}
catch (Exception e)
{
Console.WriteLine(e.ToString());
}
}
示例14: Handle
public virtual BEncodedDictionary Handle(string queryString, IPAddress remoteAddress, bool isScrape)
{
if (queryString == null)
throw new ArgumentNullException("queryString");
return Handle(ParseQuery(queryString), remoteAddress, isScrape);
}
示例15: RnetTcpConnection
/// <summary>
/// Initializes a new connection to RNET.
/// </summary>
/// <param name="ip"></param>
/// <param name="port"></param>
public RnetTcpConnection(IPAddress ip, int port)
: this(new IPEndPoint(ip, port))
{
Contract.Requires(ip != null);
Contract.Requires(port >= 0);
Contract.Requires(port <= 65535);
}