Sie sind auf Seite 1von 2

8/2/2017 Colabora.NET:ObtenerIPconVB.

NETyC#


Lo+nuevo VisualBasic6 <Xaml/> HTML/Scripts


ASP.NET Cmoen.NET ADO.NET


Lenguajes.NET Foros Windows Colaboraciones

el Guille, la Web del Visual Basic, C#, .NET y ms...

ObtenerIPconVB.NET Lasofertas
delGuille
yC# para
alojamiento
(hosting)de
Fecha:02/Feb/2005(01/02/2005)
Autor:MarioFlixGuerrero,mfguerrero@msn.com sitiosweb,
seguramente
losmejores

preciosdel
mercado
EstaesunapequeaaplicacindeconsolaparamostrarlasIPsdeunhost,recibecomoparametroelnombredel
hostenlalineadecomandos,sinorecibeesteparametro,despliegalasIPslocales,originalmenteestaescrito
enVB.NET,perovalatraduccinaC#tambien:)

CdigoenVisualBasic:

ImportsSystem.Net
ModuleModule1
SubMain()
Dimi_contAsInteger
DimHostAsString
'Sinosepasacomoparametrounnombre,muestralasiplocales
IfEnvironment.GetCommandLineArgs().Length>1Then
Host=Environment.GetCommandLineArgs(1)
Else
Host=Dns.GetHostName
http://www.elguille.info/colabora/NET2005/mfguerrero_ObtenerIP.htm 1/2
8/2/2017 Colabora.NET:ObtenerIPconVB.NETyC#
EndIf

DimIPsAsIPHostEntry=Dns.GetHostByName(Host)
DimDireccionesAsIPAddress()=IPs.AddressList

'SedespliegalalistadeIP's
Fori_cont=0Toi_cont=Direcciones.Length
Console.WriteLine("IP{0}:{1}",i_cont+1,Direcciones(i_cont).ToString())
Next
Console.Read()
EndSub
EndModule

CdigoenC#:

usingSystem
usingSystem.Net

namespaceip_cs{

classClass1{
[STAThread]
staticvoidMain(string[]args){
stringHost
string[]argumentos
//Sinosepasacomoparametrounnombre,muestralasiplocales
if(Environment.GetCommandLineArgs().Length>1){
argumentos=Environment.GetCommandLineArgs()
Host=argumentos[1]
}
else{
Host=Dns.GetHostName()
}

IPHostEntryIPs=Dns.GetHostByName(Host)
IPAddress[]Direcciones=IPs.AddressList

//SedespliegalalistadeIP's
for(inti_cont=0i_cont<Direcciones.Lengthi_cont++){
Console.WriteLine("IP{0}:{1}",i_cont+1,Direcciones[i_cont].ToString())
}
Console.Read()
}
}
}

SiestecdigotefueutilnoolvidesdarleunacalificacinenPanoramaBox:)

Espaciosdenombresusadosenelcdigodeesteartculo:

System.Net

http://www.elguille.info/colabora/NET2005/mfguerrero_ObtenerIP.htm 2/2

Das könnte Ihnen auch gefallen