Writing "using remoting technology to push messages", in which messages are pushed to the client. At this time, you must know some information about the client, such as the IP address and port. Here, we first obtain the IP address and MAC address informationCodePaste it.ArticleWait until I have time to write it again.
/**/ /// <Summary>
/// Obtain the MAC address of the Local Computer
/// </Summary>
/// <Returns> MAC address </Returns>
/// <Remarks>
/// Obtain the MAC address of the Local Computer
/// </Remarks>
Static Public String Getmacaddress ()
{
String Strmac = String . Empty;
Managementclass MC = New Managementclass ( " Win32_networkadapterconfiguration " );
Managementobjectcollection MoC = MC. getinstances ();
Foreach (Managementobject Mo In MOC)
{
If (( Bool ) Mo [ " Ipenabled " ] = True )
{
Strmac+ =Mo ["Macaddress"]. Tostring ();
}
}
Return Strmac;
}
/**/ /// <Summary>
/// Obtain the IP address of the Local Computer
/// </Summary>
/// <Returns> IP address </Returns>
/// <Remarks>
/// Obtain the IP address of the Local Computer
/// </Remarks>
Static Public String Getipaddress ()
{
String Strip = String . Empty;
Managementclass MC = New Managementclass ( " Win32_networkadapterconfiguration " );
Managementobjectcollection MoC = MC. getinstances ();
Foreach (Managementobject Mo In MOC)
{
If (( Bool ) Mo [ " Ipenabled " ] = True )
{
String [] Ipaddresses = ( String []) Mo [ " IPaddress " ];
If (Ipaddresses. Length > 0 )
Strip = Ipaddresses [ 0 ];
}
}
Return Strip;
}
/**/ /// <Summary>
/// Obtain the local computer name
/// </Summary>
/// <Returns> Local Computer Name </Returns>
/// <Remarks>
/// Obtain the local computer name
/// </Remarks>
Static Public String Gethostname ()
{
String Hostname = "" ;
Try
{
Hostname=DNS. gethostname ();
}
Catch
{
}
Return Hostname;
}
If you want to scan the Internet or want to know the MAC address of a machine in the same network segment, you need to change the method.
Thanks for the hbifts reminder. The code for using DNS to obtain the IP address is provided for your reference:
Public Static Void Getipaddress ()
{< br> iphostentry hostinfo = DNS. resolve (DNS. gethostname ();
IPaddress srcaddress = hostinfo. addresslist [ 0 ];
return srcaddress. tostring ();
}