Setup Port Forwarding on a Watchguard Firewall device

xtm2_ft

I recently put a Watchguard XTM25 on my home network.   Everything was pretty straight forward until I got to port forwarding.  I had a couple of ports I wanted forwarded to some internal addresses.  On most firewalls I’ve worked on port forwarding is typically pretty easy to find and setup.  Watchguard port forwarding is a combination of two things, one SNAT (static NAT) and a firewall policy.

So, you first want to setup the SNAT.  It’s found under the Firewall section.  Click add, give it a name and then click add under the SNAT members section.  This is where you specify the IP address of your internal client that will receive the traffic.  You aren’t specifying ports at this point.  If you have multiple clients you will be forwarding to you can create them here.  I created separate SNAT rules for each of my internal clients.  The SNAT members area seems to be able to have multiple members but I’m not sure how that works.

Capture

Next you will create a firewall policy that uses the SNAT and specifies the port you want to forward.
Navigate to the Firewall Policies section.
Click Add Policy
In the Packet Filter drop down select the protocol you want to forward.
If you are forwarding a port that’s not listed click custom then click Add and you can give it a name and specify the port.
Click Add Policy.
In the From box click Any-Trusted and click remove.
Then click the Add button under the From box and select Any then OK.
In the To box click Any-External and click Remove.
Then click the Add button under the To box and select Static NAT in the Member Type drop down.
You should see the Static NAT entry you created previously.
Select that and hit OK.
Scroll down to the bottom and click Save.

Capture

You should now have port forwarding setup for the port and client you specified!
You can recreate these steps for each of the ports you need to forward.

VB.net If then Else with a list of strings

Jpeg

In SQL server you can do an easy exclude or include list by using an in statement.
So you can do:

Select * from someTable where somecolumn in (‘somestring1’, ‘somestring2’, ‘somestring3’, ‘somestring4’)

So you only get records where the contents of somecolumn are in the specified list of strings.
I wanted to do something similiar in VB.net.
You can use an if then or statement but it can get messy.

If someStringToCheck = “somestring1” or someStringToCheck = “somestring2” or someStringToCheck = “somestring3” or someStringToCheck = “somestring4” then
…Do something blah blah…
end if

This works but what if you have a list of 20 strings you want to check for?
Through some internet searching I found this post on stackoverflow.com and came up with the following:

Dim someList = New List(Of String) From {“somestring1”, “somestring2”, “somestring3”, “somestring4”}
If someList.Contains(someStringToCheck) Then
…Do something blah blah…
else
…Do something else blah blah…
end if

It seems kind of backwards but it takes your list of strings and determines if the string you fed it is in that list.  If so do something or if not then do something else.

  • Camera: Venue 8 7840
  • Taken: 7 April, 2015
  • Aperture: ƒ/2.4
  • Focal length: 2.94mm
  • ISO: 37
  • Shutter speed: 1/85s
  • Title: Jpeg

How to sort DirectoryInfo.Getfiles array

I have an Intranet page that looks at a folder of files and lists them out.  It uses io.directoryinfo.getfiles to get the list of files but there wasn’t anyway to control the sorting.  By default it was sorting ascending but i wanted it reversed.  Here’s what I had at first:

Dim di As New IO.DirectoryInfo(Server.MapPath(“FolderofFiles”))
Dim aryFi As IO.FileInfo() = di.GetFiles(“*.pdf”)
Dim fi As IO.FileInfo
For Each fi In aryFi
..blah blah loop
Next

I tried to add Array.Sort(aryFi) but that resulted in an error:
“At least one object must implement IComparable.”

So after some internet searching I came up with the following based on a post on stackoverflow.com

First you have to create an IComparer class:

Private Class FileNameComparer
Implements System.Collections.IComparer
Public Function Compare(ByVal info1 As Object, ByVal info2 As Object) As Integer Implements System.Collections.IComparer.Compare
Dim FileInfo1 As System.IO.FileInfo = DirectCast(info1, System.IO.FileInfo)
Dim FileInfo2 As System.IO.FileInfo = DirectCast(info2, System.IO.FileInfo)
Dim Filename1 As String = FileInfo1.FullName
Dim Filename2 As String = FileInfo2.FullName
If Filename1 > Filename2 Then Return -1
If Filename1 < Filename2 Then Return 1
Return 0
End Function
End Class

Then use the comparer to sort:

Dim di As New IO.DirectoryInfo(Server.MapPath(“Folderoffiles”))
Dim aryFi As IO.FileInfo() = di.GetFiles(“*.pdf”)
Dim comparer As IComparer = New FileNameComparer()
Array.Sort(aryFi, comparer)
Dim fi As IO.FileInfo
For Each fi In aryFi
..blah blah loop
Next

The comparer I tweaked sorts the files by their filename in a descending order.  You can reverse the Return -1 and Return 1 to get them into ascending order.
Also, if you would like to sort the files by creation date you could use this comparer:

Private Class DateComparer
Implements System.Collections.IComparer
Public Function Compare(ByVal info1 As Object, ByVal info2 As Object) As Integer Implements System.Collections.IComparer.Compare
Dim FileInfo1 As System.IO.FileInfo = DirectCast(info1, System.IO.FileInfo)
Dim FileInfo2 As System.IO.FileInfo = DirectCast(info2, System.IO.FileInfo)
Dim Date1 As DateTime = FileInfo1.CreationTime
Dim Date2 As DateTime = FileInfo2.CreationTime
If Date1 > Date2 Then Return 1
If Date1 < Date2 Then Return -1
Return 0
End Function
End Class

Then you’d change:

Dim comparer As IComparer = New FileNameComparer()
to
Dim comparer As IComparer = New DateComparer()