Authorizing a program for Windows firewall in golang

polaris · · 432 次点击    
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
<p>I made a networking program with C#, and wanna port that for golang now.</p> <p>Everything is working fine now, except allowing itself for Windows firewall.</p> <p>I googled about this but nothing found..</p> <p>This is the code what i used in c# version <a href="https://pastebin.com/hNAnwh4B" rel="nofollow">https://pastebin.com/hNAnwh4B</a></p> <p>Any solutions for porting this code to golang? or any ways to allow a program itself for firewall? Thanks ))</p> <hr/>**评论:**<br/><br/>intermernet: <pre><p>Pretty sure you can do this with the powershell command <a href="https://technet.microsoft.com/en-us/itpro/powershell/windows/netsecurity/set-netfirewallrule" rel="nofollow">Set-NetFirewallRule</a> using the os/exec package to invoke powershell. </p> <p>Probably need to have elevated privileges though. </p></pre>Hexodam: <pre><p>And probably the right version of Powershell installed</p></pre>ilbekilier: <pre><p>Thank you intermernet! You did show me the way through out :))</p></pre>Bandicoon: <pre><p>If this is a program that is intended to be distributed, then I suggest leaving firewall configuration to the user. Personally and professionally I&#39;d prefer not to have applications automatically punch holes through firewalls.</p> <p>In any case, powershell via os/exec is your best plan of action. Unless you&#39;re willing to have a .NET stub purely for the purposes of opening the firewall. But then I guess then you can only open the port and not tie it to a specific program.. hmm</p></pre>ilbekilier: <pre><p>It&#39;s for internal usage. i got some computers to set configs including network settings automately, and i think powershell can make it done :)) gonna try soon. if not works, maybe i need to try with c# again... thanks for reply bandicoon</p></pre>holyjeff: <pre><p>Easiest way is to call powershell or cmds. Otherwise you need bindings to some lowe-level win32 api</p></pre>

入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889

432 次点击  
加入收藏 微博
0 回复
暂无回复
添加一条新回复 (您需要 登录 后才能回复 没有账号 ?)
  • 请尽量让自己的回复能够对别人有帮助
  • 支持 Markdown 格式, **粗体**、~~删除线~~、`单行代码`
  • 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
  • 图片支持拖拽、截图粘贴等方式上传