本文整理汇总了C#中System.Net.IPHostEntry类的典型用法代码示例。如果您正苦于以下问题:C# IPHostEntry类的具体用法?C# IPHostEntry怎么用?C# IPHostEntry使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
IPHostEntry类属于System.Net命名空间,在下文中一共展示了IPHostEntry类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Delete
public void Delete(IPHostEntry host, DirectoryInfo target)
{
var wqlQuery = new ObjectQuery(string.Format(@"SELECT * from Win32_Directory WHERE Name = '{0}'", target.Name));
var managementClassEntry = _managementClassList.First(x => x.Item1 == _hostsList.IndexOf(host));
ManagementObjectSearcher objectSearcher = new ManagementObjectSearcher(managementClassEntry.Item2.Scope, wqlQuery);
ManagementObjectCollection directoryObjectsCollection = objectSearcher.Get();
if (directoryObjectsCollection.Count == 0)
{
throw new FileSystemInstrumentationException(@"{0} {1}.", ExceptionMessages.Win32_DirectoryFail, target.Name);
}
foreach (ManagementObject shareObject in directoryObjectsCollection)
{
PropertyDataCollection outParams;
long returnValue;
managementClassEntry.Item3.Handle("Delete", new List<PropertyDataObject>(), out outParams);
returnValue = long.Parse(outParams["ReturnValue"].Value.ToString());
if (returnValue != 0)
{
throw new FileSystemInstrumentationException(@"{0} {1}.", ExceptionMessages.Win32_DirectoryFail, _errorMessageProvider.GetErrorMessage(ErrorMessageProvider.ErrorClass.Win32_Directory, returnValue));
}
}
}
示例2: GetManagementClass
public ManagementClass GetManagementClass(string scopeString, string classString, IPHostEntry hostEntry, string username, string password)
{
SetHost(hostEntry);
ValidateHost();
var connectionOptions = new ConnectionOptions()
{
Impersonation = ImpersonationLevel.Impersonate,
EnablePrivileges = true,
Username = username,
Password = password
};
var managementScope = new ManagementScope(String.Format(@"\\{0}\{1}", _host, scopeString), connectionOptions);
var managementClass = new ManagementClass(managementScope, new ManagementPath(classString), new ObjectGetOptions());
managementScope.Connect();
if (!managementScope.IsConnected)
{
throw new InstrumentationException(ExceptionMessages.ScopeConnectFail);
}
return managementClass;
}
示例3: HostNameCompletedEventArgs
public HostNameCompletedEventArgs( IPAddress ipAddress, IPHostEntry hostEntry )
{
if( ipAddress == null ) throw new NullReferenceException( "ipAddress" );
if( hostEntry == null ) throw new NullReferenceException( "hostEntry" );
_ipAddress = ipAddress;
_hostEntry = hostEntry;
}
示例4: SetHostName
private void SetHostName(IPHostEntry host)
{
if (ListView != null && ListView.InvokeRequired)
ListView.Invoke(new SetHostNameDelegate(SetHostName), host);
else if (host != null && !host.HostName.Equals(SubItems[0].Text))
Hostname = host.HostName;
}
示例5: GetEndPoint
private IPEndPoint GetEndPoint(string address, int port)
{
var host = new IPHostEntry();
host.HostName = address;
var ipAddress = Dns.GetHostAddresses(address).First();
return new IPEndPoint(ipAddress, port);
}
示例6: GetHostEndPoint
internal IPEndPoint GetHostEndPoint()
{
lock (this)
{
if (_host == null || ServicePointManager.DnsRefreshTimeout >= 0 && (DateTime.Now - _lastUpdateTime).TotalMilliseconds > ServicePointManager.DnsRefreshTimeout)
{
var uriHost = _uri.Host;
if (_uri.HostNameType == UriHostNameType.IPv6 || _uri.HostNameType == UriHostNameType.IPv4)
{
if (_uri.HostNameType == UriHostNameType.IPv6)
{
// Remove square brackets
uriHost = uriHost.Substring(1, uriHost.Length - 2);
}
_host = new IPHostEntry();
_host.AddressList = new IPAddress[] { IPAddress.Parse(uriHost) };
}
else
{
_host = Dns.GetHostEntry(uriHost);
}
_lastUpdateTime = DateTime.Now;
}
var index = ServicePointManager.EnableDnsRoundRobin ? ((uint)_index++ % _host.AddressList.Length) : _index;
return new IPEndPoint(_host.AddressList[index], _uri.Scheme == Uri.UriSchemeHttps ? (_uri.IsDefaultPort ? 443 : _uri.Port) : _uri.Port);
}
}
示例7: hostent_to_IPHostEntry
private static IPHostEntry hostent_to_IPHostEntry(string h_name, string[] h_aliases, string[] h_addrlist)
{
IPHostEntry he = new IPHostEntry();
ArrayList addrlist = new ArrayList();
he.HostName = h_name;
he.Aliases = h_aliases;
for(int i=0; i<h_addrlist.Length; i++) {
try {
IPAddress newAddress = IPAddress.Parse(h_addrlist[i]);
if( (Socket.SupportsIPv6 && newAddress.AddressFamily == AddressFamily.InterNetworkV6) ||
(Socket.SupportsIPv4 && newAddress.AddressFamily == AddressFamily.InterNetwork) )
addrlist.Add(newAddress);
} catch (ArgumentNullException) {
/* Ignore this, as the
* internal call might have
* left some blank entries at
* the end of the array
*/
}
}
if(addrlist.Count == 0)
throw new SocketException(11001);
he.AddressList = addrlist.ToArray(typeof(IPAddress)) as IPAddress[];
return he;
}
示例8: GetLocalHost
static void GetLocalHost (SimpleResolverEventArgs args)
{
//FIXME
IPHostEntry entry = new IPHostEntry ();
entry.HostName = "localhost";
entry.Aliases = EmptyStrings;
args.ResolverError = 0;
args.HostEntry = entry;
bool ipv4 = Socket.OSSupportsIPv4;
bool ipv6 = Socket.OSSupportsIPv6;
List<IPAddress> ips = new List<IPAddress> ();
if (ipv4)
ips.Add (IPAddress.Loopback);
if (ipv6)
ips.Add (IPAddress.IPv6Loopback);
foreach (NetworkInterface iface in NetworkInterface.GetAllNetworkInterfaces ()) {
if (NetworkInterfaceType.Loopback == iface.NetworkInterfaceType)
continue;
foreach (UnicastIPAddressInformation info in iface.GetIPProperties ().UnicastAddresses) {
IPAddress addr = info.Address;
AddressFamily family = addr.AddressFamily;
if ((ipv6 && AddressFamily.InterNetworkV6 == family) ||
(ipv4 && AddressFamily.InterNetwork == family)) {
ips.Add (addr);
}
}
}
entry.AddressList = ips.ToArray ();
}
示例9: GetLocalHost
void GetLocalHost (SimpleResolverEventArgs args)
{
//FIXME
IPHostEntry entry = new IPHostEntry ();
entry.HostName = "localhost";
entry.AddressList = new IPAddress [] { IPAddress.Loopback };
entry.Aliases = EmptyStrings;
args.ResolverError = 0;
args.HostEntry = entry;
return;
/*
List<IPEndPoint> eps = new List<IPEndPoint> ();
foreach (NetworkInterface iface in NetworkInterface.GetAllNetworkInterfaces ()) {
if (NetworkInterfaceType.Loopback == iface.NetworkInterfaceType)
continue;
foreach (IPAddress addr in iface.GetIPProperties ().DnsAddresses) {
if (AddressFamily.InterNetworkV6 == addr.AddressFamily)
continue;
IPEndPoint ep = new IPEndPoint (addr, 53);
if (eps.Contains (ep))
continue;
eps.Add (ep);
}
}
endpoints = eps.ToArray ();
*/
}
示例10: Connect
/// <summary>
/// Connect to Server:Port
/// </summary>
public void Connect(IPHostEntry ip, Int32 Port)
{
foreach (IPAddress addr in ip.AddressList)
{
this.Connect(addr, Port);
}
}
示例11: StartListening
public void StartListening()
{
byte[] bytes = new Byte[BufferSize];
IPHostEntry ipHostInfo = new IPHostEntry();
ipHostInfo.AddressList = new IPAddress[] { _serverIP};
IPAddress ipAddress = ipHostInfo.AddressList[0];
IPEndPoint remoteEndPoint = new IPEndPoint(ipAddress, port);
// Create a TCP/IP socket.
Socket listener = new Socket(AddressFamily.InterNetwork,
SocketType.Stream, ProtocolType.Tcp);
try
{
listener.BeginConnect(remoteEndPoint, new AsyncCallback(ConnectCallback), listener);
connectDone.WaitOne();
// receive data
receiveDone.Reset();
Receive(listener);
receiveDone.WaitOne();
Console.WriteLine("Disconnecting from feed");
listener.Shutdown(SocketShutdown.Both);
listener.Close();
}
catch (Exception e)
{
Console.WriteLine("Feed Error " + e.ToString());
}
}
示例12: NetworkDictionaryItem
internal NetworkDictionaryItem( IPAddress ipAddress, PingReply pingReply, PhysicalAddress macAddress, IPHostEntry hostEntry, IOS os )
{
_ipAddress = ipAddress;
_pingReply = pingReply;
_macAddress = macAddress;
_hostEntry = hostEntry;
_os = os;
_ports = new ConcurrentDictionary<ushort,ushort>();
}
示例13: alBuscarUsuarios
protected ArrayList alBuscarUsuarios()
{
ipHostName = Dns.GetHostEntry(Dns.GetHostName());
foreach (IPAddress ip in ipHostName.AddressList)
{
sQuery = "SELECT cuenta_usr, foto_usr FROM tabm_SGusuario T1 INNER JOIN tabt_SGsesion T2 ON T2.cod_usr = T1.cod_usr WHERE ipdir_usr= \"" + ip.ToString() + "\" LIMIT 6";
if (bAbrirConexion())
{
try
{
OdbcCommand ocComando = new OdbcCommand(sQuery, Conexion);
OdbcDataReader odcReader = ocComando.ExecuteReader();
while (odcReader.Read())
{
E_Usuario eUsuario = new E_Usuario();
eUsuario.Cuenta = odcReader[0].ToString();
eUsuario.ImagenBytes = (byte[])odcReader[1];
alResultados.Add(eUsuario);
}
vCerrarConexion();
}
catch (OdbcException ex)
{
return null;
}
}
}
return alResultados;
}
示例14: BeginInvoke
// Run the operation thread.
public void BeginInvoke(String hostName)
{
try
{
switch(operation)
{
case DnsOperation.GetHostByName:
{
acceptResult = Dns.GetHostByName(hostName);
}
break;
case DnsOperation.Resolve:
{
acceptResult = Dns.Resolve(hostName);
}
break;
}
}
catch(Exception e)
{
// Save the exception to be thrown in EndXXX.
exception = e;
}
completed = true;
if(callback != null)
{
callback(this);
}
#if ECMA_COMPAT
SocketMethods.WaitHandleSet(waitHandle);
#else
((ManualResetEvent)waitHandle).Set();
#endif
}
示例15: bComprobarFuente
public bool bComprobarFuente()
{
sQuery = "SELECT cod_usr FROM tabm_sgusuario WHERE ipdir_usr = '%.%.%.%' ";
alResultados = csFunciones.alConsultar(sQuery);
if (alResultados.Count == 0)
{
bool bBandera = false;
ipHostName = Dns.GetHostEntry(Dns.GetHostName());
foreach (IPAddress ip in ipHostName.AddressList)
{
sQuery = "SELECT cod_usr FROM tabm_sgusuario WHERE ipdir_usr = \"" + ip.ToString() + "\"";
alResultados = csFunciones.alConsultar(sQuery);
if (alResultados.Count != 0)
{
bBandera = true;
break;
}
else
{
bBandera = false;
}
}
if (bBandera == false) { MessageBox.Show("La dirección del equipo no corresponde con la cuenta", "Hotel San Carlos"); }
return bBandera;
}
else
{
return true;
}
}