Solved

Build in mini firewall

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
What .NET URL re-routing tool did I use? 2 54
Close form "before" open 3 40
jboss wildfly 10.1 10 80
HTML - Color not displaying correctly in EMAIL. 6 32
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

785 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