Solved

Build in mini firewall

Posted on 2008-06-19
7
257 Views
Last Modified: 2010-04-15
whit a code like this.

how can i filter ip's?
and set a range on witch i would like to listen too.






private void Listener()
        {
            IPEndPoint from = new IPEndPoint(IPAddress.Any, this.Port);
 
            while (true)
            {
                try
                {
                    byte[] datagram = Client.Receive(ref from);
                    string result = Encoding.UTF8.GetString(datagram);
                    ReceiveString(result);
                }
                catch
                {
                }
            }
        }

Open in new window

0
Comment
Question by:Natural_Demon
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
7 Comments
 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 21827832
you can now who the frame came from by using reading the .Address property:


                 try
                {
                    byte[] datagram = Client.Receive(ref from);
                    string result = Encoding.UTF8.GetString(datagram);
                    IPAddress addr = from.Address;

                    if (some condition using the 'addr' object)
                         ReceiveString(result);
                }

0
 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 21827833
sorry, typo, it should be:
you can know....
0
 

Author Comment

by:Natural_Demon
ID: 21827858
i'll check it out,  i'll let u hear as soon as posible.

kind regards
0
 

Author Comment

by:Natural_Demon
ID: 21828501
and how to block a ip?


kind regard
0
 
LVL 55

Accepted Solution

by:
Jaime Olivares earned 250 total points
ID: 21828544
you can do something like:

                IPAddress ip = IPAddress.Parse("1.2.3.4");

                try
                {
                    byte[] datagram = Client.Receive(ref from);
                    string result = Encoding.UTF8.GetString(datagram);
                    IPAddress addr = from.Address;

                    if ( !from.Equals(ip) )  // filter some specific IP address
                         ReceiveString(result);
                }
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question