63 thumbs up

Ordinary People Discovering Extraordinary Abilities

Not So Smart Builder

Query domain for list of computers that are listening to a specific port in c#

How can I get list of computers in a domain that are listening to a specific port (in c#)?


Would you like to answer or comment?

Sign up for a free account, or sign in (if you're already a member).
  • 1154 views
Share Send to a friend Watch Report
 

Best Answer

 
163 thumbs up

 

There is no single class or API call that will just do that. You will need to write some code and it depends on what you want to accomplish. Is this UDP or TCP? It this a specific type of service you are looking for? Maybe this particular service has a way to announce itself (like via broadcast or a centric service)? Do you have a list of IP addresses or ranges or you just want to query the entire network(s)?

And do you really need it to be a custom code? There are some excellent applications that can do just that, nmap being one of the most popular. 

If you really need to write your own code to do that, start with .Net's "System.Net.Sockets" namespace, there are classes for raw sockets and TCP/UDP clients there. You will need to do roughly the following:

  • Get a list of IP addresses - either supplied by the caller or build one yourself from your network address and class.
  • For each address, try connect to the specific port (exactly how depends on whether it's TCP or UDP). You will probably want to multi thread this if performance is an issue.
    • For TCP, SYN packet
    • For UDP, just some arbitrary packet (or if you have a specific higher level protocol you are fishing for, a specific constructed packet for that protocol)
  • Wait for response or timeout.
  • Analyze the responses. This will be different for TCP and UDP but very generally:
    • For TCP, you will probably be looking for SYN-ACK response for success
    • For UDP, you will be looking for ICMP messages for failure. absence of response doesn't mean much cause the server might be just dropping the packets.
    • Timeouts mean the port is probably closed in stealth mode or host isn't responding for other reasons.
  • Remember that even if a port is open, this doesn't mean it is open to the exact connection you are expecting (e.g. port 80 is open but listening to incoming SMTP instead of HTTP as expected). You will need to do a real "handshake" with the specific protocol to determine if that is the type or service you are looking for.

Again, all that is very much possible to do on your own but it is easier to do with utilities already tailored for that. Or try searching around for some components/libraries for C# that can do port scanning/sweeping.

 


Posted 2 years ago ( permalink )
In reply to dudushmaya's question
Rated as
Best Answer
0
5

Helpful?

line
line
line


 

Sign in to participate

Got an answer for dudushmaya? Would you like to comment on the posted answers, or vote for the one which you think is the best?

Sign up for a free account, or sign in (if you're already a member).

Explore Related Questions

Other people asked questions on similar topics, check out the answers they received:


In c# how can I response with unicode and not utf ...

in c# in fuction of web service how can I response with unicode and not utf_8
Submitted by zivavi 1 year ago
  • viewed 1378 times

Last answer posted 7 months ago by Dollar


Hi, Do you have a sample C# code to use google or ...

Hi, Do you have a sample C# code to use google or yahoo id to signup/login to the website? please reply me at prasadvemala@gmail ...
Submitted by prasad 28 days ago
  • viewed 30 times

Last answer posted 14 days ago by prasad


Debugging c# without Visual-Studio installed?

How do I debug .NET application when Visual-Studio is not installed? Is there an independant debugging utility for C#, as WinDBG ...
Submitted by Paz 8 months ago
  • viewed 811 times

Last answer posted 8 months ago by Eran



» More...

Explore Related Posts in Forums

C-c-c-om c-c-c-a-a-a-s-s-t-t

I currently have Comcast in Montgomery County, MD and I've noticed a lot of stuttering of late... late. It happens on numerous channels, once or perhaps twice per hour the show I'm watching...

C-C-C-C-C-C-Combo Breaker!

I know MS bought out RARE.... but I long for this series to come back. Better yet, if some... of the original dev team members broke away and decided to bring something similar to multi...

comment latex C-c C-c?

: Hi, How can I set my emacs configuration so that when in LaTeX mode, "C-c C-c" will comment out the lines with ("%") as does comment it in other modes? Right now, when I do "C-c C-c", I get
» More...
Powered by
Feed - Subscribe to changes to this Q&A Blog

Explore Related Videos

Watch: Full-Length Vice Presidential Debate

Vice Presidential candidates Sen. Joe Biden (D-Del.) and Gov. Sarah Palin (R-Alaska) squared off in a highly anticipated debate Thursday, Oct. 2nd in St. Louis, Mo.

No. 13 South Florida Crushes N.C. State,...

Grothe, No. 13 South Florida rough up N.C. State

Joe Biden at the Democratic National Jewish...

Joe Biden gives a speech at the Democratic National Jewish Convention in Washington, D.C.

Watch the Full Debate

Candidates John McCain (R-Ariz.) and Barack Obama (D-Ill.) participated in the first of three presidential debates on Friday, September 26th at the University of Mississippi. Though the intended topics were national security and foreign policy, the economy was at the forefront. Video by AP

Mr. Solo (Pilot)

The Technological Hierarchy for the Removal of Undesirables and the Subjugation of Humanity (THRUSH) launches an attack on the New York headquarters of the United Network Command for Law-Enforcement (UNCLE) in order to kill Alexander Waverly, head of the agency. But the THRUSH agents are caught when they try to enter the headquarters building, and rather than be apprehended, they do themselves in by consuming poison. The assassination attempt was made because Waverly has become aware of the plot by THRUSH murderer Andrew Vulcan to murder a visiting dignitary, Premier Ashumen of Natumba. To stop him, top UNCLE agents Napoleon Solo and Illya Kuryakin are sent to prevent any harm coming to the African leader.

Ogm + hormones = monstruosite_(vo)

http://worldwide.familyradio.org/fr/mp3/bible/ http://pagesperso-orange.fr/pensee.sauvage/telechrg/albrtg.pdf http://www.tarot.org.il/Library/Levi/Clavicules%20de%20Salomon.pdf http://www.hermetics.org/pdf/magic/DogmaEtRituel_Part_I.pdf http://www.rue89.com/ http://www.spike.com/video/infrared-goggle-hack/2880432?cmpnid=800&lkdes=VID_2880432 http://www.20minutes.fr/article/240345/Monde-Les-Americains-utilisent-le-plus-souvent-leur-arme-contre-eux-memes.php http://www.dailymotion.com/related/3367177/video/x28ket_offensive-de-creationistes-us_politics http://img530.imageshack.us/img530/7451/sarkornu2sy3.jpg http://www.dailymotion.com/relevance/search/Les%2Bnouvelles%2Barmes/video/x5pai2_bombes-a-fragmentation-irak-12_news http://www.dailymotion.com/relevance/search/Les%2Bnouvelles%2Barmes/video/x5bsvk_les-nouvelles-armes-12_webcam ttp://www.dailymotion.com/fr/featured/video/x5ucg9_excerpt-state-of-the-forest_shortfilms http://www.dailymotion.com/relevance/search/ICEBERG/video/x5gezx_iceberg-carre_news http://www.ordinateurs-de-vote.org/IMG/pdf/Qui_controle_le_vote_electronique.pdf http://www.dailymotion.com/relevance/search/jesus%2Bde%2Bnazareth/video/x3ogjt_jesus-de-nazareth-partie-1_family http://www.spiritist.org/larevuespirite/revue55.pdf http://www.onnouscachetout.com/themes/technologie/orion-valerian.php http://quantumfuture.net/fr/organicportals1_fr.htm

Four Killed in Crash of Md. Rescue Helicopter

A Maryland State Police rescue helicopter goes down in bad weather in Walker Mill Regional Park in Prince George's County. The helicopter had just picked up two victims of a car crash in Southern Maryland and was carrying five people, four of whom died. Video by News Channel 8

Fix Cam: Debate Night!

Read The Fix Video by Chris Cillizza / washingtonpost.com

Bill Clinton Holds First Rallies for Obama

Former President Bill Clinton hosts "Change We Need" rallies Wednesday in Orlando and Fort Pierce to support Sen. Barack Obama's presidential campaign. It's the first time Clinton has campaigned for Obama. Video by AP
» More...
Powered by
Copyright © 2006-2008, Yedda Inc. and respective copyright owners · CC License