Click here to Skip to main content
Licence 
First Posted 5 Jan 2007
Views 51,711
Downloads 468
Bookmarked 21 times

Useful Lite Effective Firewall .NET

By | 5 Jan 2007 | Article
Take control of your computer using iphlpapi.dll

Introduction

This goal of this article is to show how anyone can implement their own firewall using iphlpapi.dll. I have included a BUGGY and not fully functional GUI to show you the way. If you do implement a better GUI, I will be happy to replace the one I included here.

[DllImport("iphlpapi.dll", EntryPoint = "PfCreateInterface")]
        public static extern int PfCreateInterface(
                                        int dwName,
                                        PFFORWARD_ACTION inAction,
                                        PFFORWARD_ACTION outAction,
                                        bool UseLog,
                                        bool MustBeUnique,
                                        ref IntPtr ppInterface
                                        );

        [DllImport("iphlpapi.dll", EntryPoint = "PfDeleteInterface")]
        public static extern int PfDeleteInterface(
                                        IntPtr pInterface
                                        );

        [DllImport("iphlpapi.dll", EntryPoint = "PfBindInterfaceToIndex")]
        public static extern int PfBindInterfaceToIndex(
                                        IntPtr Interface_handle,
                                        int dwIndex,
                                        PFADDRESSTYPE pfatLinkType,
                                        ref int LinkIPAddress
                                        );

        [DllImport("iphlpapi.dll", EntryPoint = "PfBindInterfaceToIPAddress")]
        public static extern int PfBindInterfaceToIPAddress(
                                        IntPtr Interface_handle,
                                        PFADDRESSTYPE pfatType,
                                        ref int ip_address
                                        );

        [DllImport("iphlpapi.dll", EntryPoint = "PfUnBindInterface")]
        public static extern int PfUnBindInterface(
                                        IntPtr pInterface
                                        );

        [DllImport("iphlpapi.dll", EntryPoint = "PfAddFiltersToInterface")]
        public static extern int PfAddFiltersToInterface(
                                        IntPtr interface_handle,
                                        int cInFilters,
                                        [MarshalAsAttribute(UnmanagedType.Struct)] 
                                        ref PPF_FILTER_DESCRIPTOR pfiltIn,
                                        int cOutFilters,
                                        [MarshalAsAttribute(UnmanagedType.Struct)]
                                        ref PPF_FILTER_DESCRIPTOR pfiltOut,
                                        [MarshalAsAttribute(UnmanagedType.Struct)]
                                        ref PPF_FILTER_DESCRIPTOR pfHandle
                                        );

        [DllImport("iphlpapi.dll", EntryPoint = "PfRemoveFiltersFromInterface")]
        public static extern int PfRemoveFiltersFromInterface(
                                        IntPtr ih,
                                        int cInFilters,
                                        [MarshalAsAttribute(UnmanagedType.Struct)]
                                        ref PPF_FILTER_DESCRIPTOR pfiltIn,
                                        int cOutFilters,
                                        [MarshalAsAttribute(UnmanagedType.Struct)]
                                        ref PPF_FILTER_DESCRIPTOR pfiltOut
                                        );

        [DllImport("iphlpapi.dll", EntryPoint = "PfRemoveFilterHandles")]
        public static extern int PfRemoveFilterHandles(
                                        IntPtr interface_handle,
                                        int count_Filters,
                                        [MarshalAsAttribute(UnmanagedType.Struct)] 
                                        ref PPF_FILTER_DESCRIPTOR pvHandles
                                        );

        [DllImport("iphlpapi.dll", EntryPoint = "PfRebindFilters")]
        public static extern int PfRebindFilters(
                                        IntPtr pInterface,
                                        [MarshalAsAttribute(UnmanagedType.Struct)]
                                        ref PPF_LATEBIND_INFO pLateBindInfo
                                        );

        [DllImport("iphlpapi.dll", EntryPoint = "PPfAddGlobalFilterToInterface")]
        public static extern int PfAddGlobalFilterToInterface(
                                        IntPtr interface_handle,
                                        [MarshalAsAttribute(UnmanagedType.Struct)]
                                        ref GLOBAL_FILTER gfFilter
                                        );

        [DllImport("iphlpapi.dll", EntryPoint = "PfRemoveGlobalFilterFromInterface")]
        public static extern int PfRemoveGlobalFilterFromInterface(
                                        IntPtr interface_handle,
                                        [MarshalAsAttribute(UnmanagedType.Struct)]
                                        ref GLOBAL_FILTER gfFilter
                                        );

        [DllImport("iphlpapi.dll", EntryPoint = "SetIpTTL")]
        public static extern int SetIpTTL(uint ttl);

History

  • 5th January, 2007: Initial post

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

Oz Jundi

Engineer
TECO GROUP - Jundi Electrical Industry
United States United States

Member

if you have any questions please send an email :
 
ojundi @ [%s].info
 
Oz [Jundi]

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
Questionthanks for the api functions PinmemberDamian 223:50 28 Sep '11  
Questionnot work!!!! Pinmembersalar_master3:02 29 Aug '11  
QuestionBlock All ports except one for a specified IP Pinmemberqinta9:50 12 Nov '09  
General测试 Pinmembervanery16:07 29 Jun '09  
Generalhello~ PinmemberBok Deuk Song0:49 27 May '09  
GeneralGood One but.... Pinmemberjazznewbie13:07 11 Mar '09  
GeneralRe: Good One but.... Pinmemberjazznewbie13:26 11 Mar '09  
GeneralRe: Good One but.... Pinmemberjazznewbie2:11 19 Mar '09  
GeneralNo interfaces showing PinmemberPaul Rabe23:59 9 Feb '09  
GeneralI also get the stack exception 6 Pinmemberblipsnart5:52 23 Nov '07  
GeneralYeah! PinmemberRunnerDude8:32 6 Jul '07  
QuestionVista: Error 120 [modified] PinmemberRichardBPutnam6:06 23 May '07  
AnswerRe: Vista: Error 120 Pinmemberjjkaczor14:35 16 Nov '07  
GeneralRe: Vista: Error 120 PinmemberRichardBPutnam5:10 19 Nov '07  
GeneralRe: Vista: Error 120 Pinmemberpowerranger1237:53 22 Mar '09  
QuestionCould not add filter 6 Pinmemberbcodebcode10:47 25 Jan '07  
AnswerRe: Could not add filter 6 PinmemberOz Jundi16:09 25 Jan '07  
GeneralRe: Could not add filter 6 Pinmemberbcodebcode4:09 26 Jan '07  
GeneralRe: Could not add filter 6 Pinmemberyoney mike9:57 21 May '07  
GeneralRe: Could not add filter 6 PinmemberMember 402502215:18 30 Dec '07  
GeneralProblem About Tho Most Simplest FireWall Pinmemberumut_842:32 16 Jan '07  
GeneralWOW! PinmemberHawk77721:00 8 Jan '07  
For the longest time I've wondered... where the heck are the API functions that firewalls use to hook into the routing system?! Finally, I have my answer. I think I may go and write a firewall now. You have a 5 just for showing the name of the DLL and a couple of function declarations. Thanks!
GeneralFree Firewalls PinmemberVasudevan Deepak Kumar21:51 5 Jan '07  
GeneralRe: Free Firewalls PinmemberOz Jundi6:16 6 Jan '07  
GeneralRe: Free Firewalls PinmemberThomas Fanell10:57 8 Jan '07  

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Mobile
Web02 | 2.5.120529.1 | Last Updated 5 Jan 2007
Article Copyright 2007 by Oz Jundi
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid