Solved

Build in mini firewall

Posted on 2008-06-19
7
248 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
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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

863 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

21 Experts available now in Live!

Get 1:1 Help Now