Sign up to the jQuery Grid Subscription list.

Creating a FireWall Program

Original post by mjwsoft at http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=2511013&SiteID=1

The Question :


Is it possible to program an AV or Firewall in VB Express 2005?


The Accepted answer by Martin Xie - MSFT

Hi mjwsoft,

I agree with spotty. C++ may be more suitable for programming Firewall.

If you wish to do it in VB.NET, you need to P/Invoke Packet Filtering API.

The Firewall service usually is based on packet filtering technology.

Here are some references.

1. Simple Packet - Filter Firewall

Working of firewall is based on the following steps:

  • Extract the packet header
  • Check the protocol associated
  • Compare with the rules
  • Check the source and destination add. If protocol is same
  • Check out the port if protocol is TCP
  • Drop or pass the packet

2. Packet Filtering API on MSDN

http://msdn2.microsoft.com/en-us/library/Aa376636.aspx

Packet Filtering API allow us to associate filters to IP adapter interfaces. We can implement a functionality similar that included in TCP/IP filter options in TCP/IP properties of a network adapter.

3. Packet Filtering in .NET

Class library to implement packet filtering funcionality in your .NET applications

4. In addition, here is a Firewall SDK which helps deveopers create and manage a firewall control easily.

The Gtfctrl.dll wraps all the firewall operations in one "Firewall Panel", it can be used in VB.Net , C#.Net.

http://www.xanv.com/firewall-sdk.html

5. You also can find some ideas in this thread.

How to build a firewall like AVG Firewall in c#

6. The basics of a firewall

Best regards,

Martin




Great Web Site for DotNet Developers

Hi Code Searcher,
I just found a great web site by searching the MSDN Forums.
I suddenly found a great website : http://www.getfreebudget.com/DevCntr.htm made by Jeff an active MSDN forums member.
It contains hundred of samples controls and lot more.
Take your time visiting it.

New Feature in MSDN Forum Tracker

Hi Developer,

I had just add a new feature for the MSDN Forum Tracker Blog.
Now Good Code snippet will be converted depending on their langauge. If it's VB.net then it will be C# and Vice Versa.
This will help both VB.net and C# developer get the tragted code without looping in different code engine convertion.

Our Code Convertion is powered by Developer Fusion, you can find it here : http://labs.developerfusion.co.uk

If you have other suggestion, don't hesitate post a comment!

Convert Binary To Ascii

Original post by Spaceman1972 at http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=2160524&SiteID=1


The Question :

Hi,

I am reading some binary data through my COM Port.

On my form are 2 multi-line text boxes and 14 single line text boxes.

Currently I convert the binary data into hex and display it in one of the multi-line text boxes.

I convert the binary data into hex as each byte is read and then display it.

I would like to also display the binary data into ascii in the other multi-line text box. And also split the whole ascii string into substrings at certain points and display each one in the single line text boxes. I would like to process this all at the same time? How can this be done?

Cheers

Mark



The Accepted Answer (By Martin Xie - MSFT)

Hi Mark,

Spaceman1972 wrote:

Currently I convert the binary data into hex and display it in one of the multi-line text boxes.

I convert the binary data into hex as each byte is read and then display it.

By means of Convert class, you can first convert Binary to Decimal Intger, and then convert Decimal to Hexadecimal string, finally assign it to the TextBox.Text property.

Code Snippet

Imports Microsoft.VisualBasic

Imports System

Imports System.Collections.Generic

Imports System.Text

Dim bin As String = "1000001" 'Binary string

Dim decimalValue As Integer

Dim hexValue As String

decimalValue = Convert.ToInt32(bin, 2) 'First convert Binary to Decimal Intger

hexValue = Hex(decimalValue) 'Convert Decimal to Hexadecimal string

TextBox.Text = hexValue 'Display it in the multi-line textbox



Spaceman1972 wrote:

I would like to also display the binary data into ascii in the other multi-line text box. And also split the whole ascii string into substrings at certain points and display each one in the single line text boxes. I would like to process this all at the same time? How can this be done?

You can first convert Binary data to Decimal Intger (as ASCII Codes), and then convert ASCII Codes to ASCII Characters, finally assign it to the TextBox.Text property.

Code Snippet

Dim bin As String = "1000001" 'Binary string (A's ASCII Code 65)

Dim decimalAscIIValue As Integer

decimalAscIIValue = Convert.ToInt32(bin, 2) 'First convert Binary to Decimal Intger

Dim AscIIChar As String = Chr(decimalAscIIValue) 'Then convert Decimal to ASCII Character

TextBox.Text = AscIIChar 'AscIIChar =A. Display it in the multi-line textbox

I hope this can enlighten you.

I believe you can finish the rest task.

Best regards,

Martin Xie

Getting all the possible combinations of numbers

Original post by rattlesnake316 at http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=2144742&SiteID=1

The Question :

How can I get all the possible combinations of numbers?

For example the input numbers are 1, 2 and 3

How can i get all the possible combinations of these numbers

For example
1 2 3
3 2 1
3 1 2
2 1 3
2 3 1
1 3 2

How can i get all of this??? The numbers depends on the input for example the input numbers are from 1 - 9
how can i get all the possible combinations for that.

Hope someone could help me out here...

Thanks in advance!

The Best Answer by
Robert Rossney :

Recursion is the key. To find all of the permutations of an n-element set, find, for each element in the set, all of the permutations of the n-element subset that doesn't contain that element.

Here's an implementation. It's not very efficient (an efficient algorithm would keep the current permutation in an array that it passes by reference, instead of accumulating it in a string), but it's correct:

Code Snippet

class Program

{

static int count;

static void Main(string[] args)

{

char[] set = new char [] { 'a', 'b', 'c' };

FindPermutations(String.Empty, set);

Console.WriteLine("{0} permutations found", count);

Console.ReadLine();

}

static void FindPermutations(string permutation, char[] set)

{

if (set.Length == 1)

{

Console.WriteLine(permutation + set[0]);

count++;

return;

}

for (int i = 0; i <>

{

char n = set[i];

string newPermutation = permutation + n;

char[] subset = new char[set.Length - 1];

int j = 0;

for (int k = 0; k <>

{

if (set[k] != n)

{

subset[j++] = set[k];

}

}

FindPermutations(newPermutation, subset);

}

}

}

The Code converted to VB.net

Class Program
Shared count As Integer
PrivateSharedSub Main(ByVal args As String())
Dim [set] As Char() = New Char() {"a"C, "b"C, "c"C}
FindPermutations([String].Empty, [set])
Console.WriteLine("{0} permutations found", count)
Console.ReadLine()
EndSub
PrivateSharedSub FindPermutations(ByVal permutation As String, ByVal [set] As Char())
If [set].Length = 1 Then
Console.WriteLine(permutation + [set](0))
count += 1
Return
EndIf
For i As Integer = 0 To [set].Length - 1
Dim n As Char = [set](i)
Dim newPermutation As String = permutation + n
Dim subset As Char() = New Char([set].Length - 2) {}
Dim j As Integer = 0
For k As Integer = 0 To [set].Length - 1
If [set](k) <> n Then
subset(System.Math.Max(System.Threading.Interlocked.Increment(j),j - 1)) = [set](k)
EndIf
Next
FindPermutations(newPermutation, subset)
Next
EndSub
EndClass