2
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 for me to 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 an IP address of class C, in order to send the broadcast just change the last Octeto to 255.
It is possible to get this ip address automatically regardless of the network where the program runs?
I wanted to avoid the "fastidious" process of processing text with the strings associated with ip and its mask.
I did not understand very well what you want, it would be to get the IP address of a computer network automatically?
– gato
Voce wants to send a broadcast message so that all hosts connected to the network receive and this?
– user45474
Yes ... but I don’t want to have to write the ip address of the network where I am in the code.
– gtpt
if Voce is wanting to get the network mask automatically I do not know if with socket is possible but with threads of the system probably yes
– user45474
I am also forgetting that a host may have more than one interface ... which further complicates the scenario.
– gtpt