CodeBetter.Com
CodeBetter.Com
RSS 2.0 via Feedburner
           Do you Twitter? Follow us @CodeBetter

Ranjan Sakalley


Get IP Addresses of all machines in your network

I searched the .Net BCL for a solution to this, and then I had to go back to net.exe to do this. This is a very brittle solution, so if you have a better one, dont forget to enlighten me.

using System;

using System.IO;

using System.Diagnostics;

using System.Net;

using System.Net.Sockets;

using System.Collections.Specialized;

namespace NetworkIPs

{

public class Names

{

public StringCollection GetNames()

{

ProcessStartInfo _startInfo = new ProcessStartInfo("net","view");

_startInfo.CreateNoWindow = true;

_startInfo.UseShellExecute = false;

_startInfo.RedirectStandardOutput = true;

Process _process = Process.Start(_startInfo);

StreamReader _reader = _process.StandardOutput;

StringCollection _machineNames = GetMachineNamesFromProcessOutput(_reader.ReadToEnd());

StringCollection _machineIPs = new StringCollection();

foreach(string machine in _machineNames)

{

_machineIPs.Add(IPAddresses(machine));

}

return _machineIPs;

}

private static string IPAddresses(string server)

{

try

{

System.Text.ASCIIEncoding ASCII = new System.Text.ASCIIEncoding();

// Get server related information.

IPHostEntry heserver = Dns.Resolve(server);

//assumin the machine has only one IP address

return heserver.AddressList[0].ToString();

}

catch

{

return "Address Retrieval error for " + server ;

}

}

//string manipulations

private StringCollection GetMachineNamesFromProcessOutput(string processOutput)

{

string _allMachines = processOutput.Substring( processOutput.IndexOf("\\"));

StringCollection _machines= new StringCollection();

while(_allMachines.IndexOf("\\") != -1 )

{

_machines.Add(_allMachines.Substring(_allMachines.IndexOf("\\"),

_allMachines.IndexOf(" ",_allMachines.IndexOf("\\")) - _allMachines.IndexOf("\\")).Replace("\\",String.Empty));

_allMachines = _allMachines.Substring(_allMachines.IndexOf(" ",_allMachines.IndexOf("\\") + 1));

}

return _machines;

}

}

public class Runner

{

static void Main()

{

Names _names = new Names();

StringCollection names = _names.GetNames();

foreach(string name in names)

Console.WriteLine(name);

Console.ReadLine();

}

}

}


Published Jan 21 2005, 01:46 AM by rsakalley
Filed under:

Comments

NeVaL said:

http://www.lila-org.beibi.info ^^^ http://www.linda-l.beibi.info ^^^ http://www.portrett-snill-pupper.biseksuell.info ^^^ http://www.knulle-pornostjerne-image.biseksuell.info ^^^ http://www.portrett-snill-pupper.erotiska.info ^^^ http://www.knulle-pornostjerne-image.erotiska.info ^^^ http://www.soffbord-modern-design.fitta69.info ^^^ http://www.bild-bitch-utmrkt.fitta69.info ^^^ http://www.kuk-brutal-porr.fotsex.info ^^^ http://www.galleri-jungfru-mogen.fotsex.info ^^^ http://www.onnistunut-hetkellinen.isomuna.info ^^^ http://www.sperma-mouth-ilmasto.isomuna.info ^^^ http://www.portto-wendel-orgasmi.laukeaminen.info ^^^ http://www.pillu-sperma.laukeaminen.info ^^^ http://www.foto-bilde-fitte.rype.info ^^^ http://www.portrett-escorte-seoul.rype.info ^^^ http://www.klipp-virgin-jente.sadsprut.info ^^^ http://www.pen-bilde-sexy.sadsprut.info ^^^ http://www.otos-sperm-colage.tytsy.info ^^^ http://www.porno-svarta-fitta.tytsy.info ^^^ http://www.anl-fucking-videos.18analsex.com ^^^ http://www.anal-foto-sesso.18analsex.com ^^^ http://www.avventura-perverse-xxx.pazzesesso.com ^^^ http://www.sedere-nero-immagine.pazzesesso.com ^^^ http://www.wifey-busty-porno.figanere.com ^^^ http://www.filmato-tettina-18.figanere.com ^^^ http://www.porca-ingorda-clip.inculatexxx.com ^^^ http://www.film-biondo-bologna.inculatexxx.com ^^^ http://www.vecchia-tardone-film.prostitutaculo.com ^^^ http://www.foto-mutandine-moglie.prostitutaculo.com ^^^ http://www.frocio-giovane-orgia.lesbicastrip.com ^^^ http://www.mpgs-ragazzine-pompinare.lesbicastrip.com ^^^ http://www.hentai-fuerte-video.007sexogratis.com ^^^ http://www.actriz-mexicana-galeria.007sexogratis.com ^^^ http://www.dvd-veronica-pagacova.3sexogratis.com ^^^ http://www.pic-nina-hot.3sexogratis.com ^^^ http://www.espaniol-colombianas-desnuda.analsexogratis.com ^^^ http://www.preview-caracteristica-masajista.analsexogratis.com ^^^ http://www.chavitas-calientes-gif.cam-sexo-gratis.com ^^^ http://www.mpgs-todomaduras-com.cam-sexo-gratis.com ^^^

# December 28, 2006 6:09 AM

Smułko said:

http://hotel-leoni-rimini.ef9iyw6m643.info/

http://cartomanzia-consulto.nvovay9vegv.info/

http://ritirarsi-amatoriali-urinate.crlawhxqgwi.info/

http://www.wuagpgr8vhh.info/agriturismo-torino.html

http://voip-provider.1okkjnwrl2i.info/

http://fine-lesbiche-anale-fotti.crlawhxqgwi.info/

http://gradito-cowgirl-doppio-penetrazione.o8nr6j39nzr.info/

http://itfuv8o977.u3yomyk50cp.info/

http://148573388.zp9as3i9llc.info/

http://lovable-asiatiche-amore.79pkaqzrpg2.info/

http://edile-toscana.kmxb954ry0e.info/

http://www.2qhtadoaxcg.info/offerta-sardegna-giugno/

http://www.1okkjnwrl2i.info/patio-heater.html

http://municipalita-venezia.cn3u6te3gqn.info/

http://abbigliamento-donna-list.ef9iyw6m643.info/

http://spavaldo-giovane-merda.101qprrep2h.info/

http://spaventoso-medio.u4re8o6n1qf.info/

http://www.2qhtadoaxcg.info/appunti-inglese.html

http://loredana-bontempi.wuagpgr8vhh.info/

http://goodly-segretaria-strip.6919xh4uvc3.info/

http://www.jht3k7963m7.info/amicizia-annuncio-personali/

http://alessia-merz.7djyd626ukf.info/

http://schioccare-figlia.u4re8o6n1qf.info/

http://j35t131.u3yomyk50cp.info/http://molto-bollente-economico.worri.org.es/

http://wellness-bergamo.vtya.com.es/

http://www.bomet.nom.es/capo-cowgirl-inculate.html

http://www.i-s-t.nom.es/hotel-eleganti-bergamo.html

http://www.quad.org.es/good-looking-agente-di-polizia-schizzate-di-figa.html

http://www.psaro.com.es/suoneria-polifonica-cantate.html

http://www.bolid.nom.es/piu-bollente-sentimento-orale.html

http://www.ntex.nom.es/lesbiche-che-si-sculacciano.html

http://www.dindl.nom.es/voli-zurigo.html

http://gradevole-cowgirl-inculate.vtya.com.es/

http://www.quad.org.es/window-media-center.html

http://www.cdoc.nom.es/oukdo51v/

http://f46emed5kor.cemaf.org.es/

http://www.arteg.nom.es/2z4pcll.html

http://www.cabtf.nom.es/giovane-sex-in-anticamera.html

http://www.miclo.com.es/pisciate-nel-culo.html

http://www.azvu.nom.es/terreni-veneto.html

http://www.bibbo.com.es/oglxusw/

http://www.pipes.org.es/casa-mare-toscana.html

http://www.psaro.com.es/molto-bollente-inchiodare-papy.html

# January 24, 2007 1:28 AM

Leave a Comment

(required)  
(optional)
(required)  

Enter the numbers above:
Add
Check out Devlicio.us!

Our Sponsors

Free Tech Publications