Solved

Build in mini firewall

Posted on 2008-06-19
7
246 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
  • 3
  • 2
7 Comments
 
LVL 55

Expert Comment

by:Jaime Olivares
Comment Utility
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
Comment Utility
sorry, typo, it should be:
you can know....
0
 

Author Comment

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

kind regards
0
 

Author Comment

by:Natural_Demon
Comment Utility
and how to block a ip?


kind regard
0
 
LVL 55

Accepted Solution

by:
Jaime Olivares earned 250 total points
Comment Utility
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 Gift Card with Acronis Backup Purchase!

Backup any data in any location: local and remote systems, physical and virtual servers, private and public clouds, Macs and PCs, tablets and mobile devices, & more! For limited time only, buy any Acronis backup products and get a FREE Amazon/Best Buy gift card worth up to $200!

Join & Write a Comment

In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
This video discusses moving either the default database or any database to a new volume.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

771 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now