Solved

Build in mini firewall

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

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

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

We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
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!
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

856 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