My Wi-Fi network interface contains the following settings:
Wireless LAN adapter Wi-Fi:
Connection-specific DNS Suffix . : home
Link-local IPv6 Address . . . . . : fe80::95d7:bda0:eac3:ebf7%5
IPv4 Address. . . . . . . . . . . : 192.168.1.2
Subnet Mask . . . . . . . . . . . : 255.255.255.0
Default Gateway . . . . . . . . . : 192.168.1.1
One way I send a text stream is by using the UDP protocol.
using System;
using System.Net;
using System.Net.Sockets;using System.Text;
class Program
{
static void Main(string[] args)
{
Socket emissor = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
IPAddress destinatario = IPAddress.Parse("192.168.1.255");
IPEndPoint emissor_end_point = new IPEndPoint(destinatario, 33333);
Console.WriteLine("Digite a mensagem a enviar:");
string mensagem = Console.ReadLine();
byte[] mensagem_buffer = Encoding.ASCII.GetBytes(mensagem);
emissor.SendTo(mensagem_buffer, emissor_end_point);
emissor.Close();
Console.WriteLine("Mensagem enviada ...");
Console.ReadKey();
}
}
In the case of a class C ip address, in order to send the message in broadcast just change the last octet to 255.
Is it possible to get this ip address automatically, regardless of the network where the program runs?
I wanted to avoid the "fastidious" process of rendering text with the strings associated with ip and its mask.