Linux 下指定端口开放访问权限

原文地址:

CentOS 开放指定端口

例如要开放 8808 端口,执行

firewall-cmd --zone=public --add-port=8888/tcp --permanent

其中
--zone 表示作用域;

--add-port=8808/tcp 表示指定开放的端口,其格式为【端口/通讯协议】

--permanent 表示永久生效,如果没有配置此参数,重启后配置会失效。

然后重启防火墙

firewall-cmd --reload

查看防火墙规则,用如下命令

iptables -L

Debian 系开放指定端口

首先,需要安装 iptables,执行

apt-get update
apt-get install iptables

假设要开放 8088 端口,执行

iptables -I INPUT -p tcp --dport 8888 -j ACCEPT

然后保存规则

iptables-save

设置完就已经开放了指定的端口,但重启后会失效,下面设置持续生效规则;

安装 iptables-persistent

apt-get install iptables-persistent

然后执行如下两个命令

netfilter-persistent save
netfilter-persistent reload

设置完成后,即使重启,配置也不会失效。

Original: https://www.cnblogs.com/greyzeng/p/16796899.html
Author: Grey Zeng
Title: Linux 下指定端口开放访问权限



相关阅读

Title: python 入门到实践第十二章 游戏不响应_Python实战【用Python写游戏第十二节】屡败屡战…

欢迎大家来到Python自学教程实战篇,我们上一讲处理敌机与本体之间的碰撞检测,决定了游戏是否结束,但是结束的反馈是什么呢?我这一局玩得怎样呢?我怎么才能重新开始下一局游戏呢?这便是我们本节课需要学习的内容,大家一起来看一下吧:

今天还将增加两个功能,让它看起来更完整:显示分数和重新开始。通过这种方式,玩家可以一次又一次地玩。

[En]

Two more features will be added today to make it look more complete: show scores and start over. In this way, players can play again and again.

要显示分数,您必须首先有一个变量来记录分数:

[En]

To display the score, you must first have a variable to record the score:

score = 0

当打中敌机的时候,把分数增加。为了达到这个目的,修改一下之前的checkHit函数,让它和checkCrash一样,返回一个bool值,表示是否发生了碰撞:

def checkHit(enemy, bullet):

if (bullet.x > enemy.x and bullet.x < enemy.x + enemy.image.get_width()) and (

bullet.y > enemy.y and bullet.y < enemy.y + enemy.image.get_height()

):

enemy.restart()

bullet.active = False

增加返回值

return True

return False

在主循环里,当checkHit为True时,就增加分数:

for b in bullets:

if b.active:

for e in enemies:

击中敌机后,分数加100

if checkHit(e, b):

score += 100

b.move()

screen.blit(b.image, (b.x, b.y))

这样,就用score记录了游戏中的分数。

在pygame中要显示文字,不能直接print,那样只会在命令行里输出,无法显示在屏幕上。需要先创建一个font对象:

font = pygame.font.Font(None, 32)

None表示使用默认字体,32是字号。

然后,用font渲染出字体,再绘制到screen上:

text = font.render(“Socre: %d” % score, 1, (0, 0, 0))

screen.blit(text, (0, 0))

(0,0)是屏幕左上角的位置。

当游戏结束时,我们需要在屏幕中央显示比分并更改坐标。

[En]

When the game is over, we need to display the score in the middle of the screen and change the coordinates.

为了便于在游戏结束后重新开始,让我们在事件响应的代码中添加一段处理:

[En]

To make it easy to start over after the game is over, let’s add a piece of processing to the code for the event response:

判断在gameover状态下点击了鼠标

if gameover and event.type == pygame.MOUSEBUTTONUP:

重置游戏

plane.restart()

for e in enemies:

e.restart()

for b in bullets:

b.active = False

score = 0

gameover = False

当gameover状态下发生了鼠标按钮抬起的事件(即玩家点击了鼠标),我们就把本体和敌机都重置位置,子弹都设active为False,分数清零,gameover为False,游戏重新开始。

那么,现在你可以一次又一次地与敌机战斗,然后一次又一次地被摧毁。次数是没有限制的。你不必向你的朋友要飞机。至于最高分的记录,我想你也能应付。

[En]

Well, now you can fight the enemy plane again and again, and be destroyed again and again. There is no limit to the number of times. You don’t have to ask your friends for a plane. As for the record of the highest score, I think you can also handle it.

恭喜您在Python自学的道路上又坚持了一天,我们目前学习的知识比之前的要复杂一些,但是也比之前的有趣多了,所以希望大家跟上我们的步伐,继续加油!

免责声明:内容和图片均来自互联网,版权归原作者所有。如果您的原创版权受到侵犯,请告知我们,我们将尽快删除相关内容。

[En]

Disclaimer: the content and pictures are from the Internet, and the copyright belongs to the original author. If there is any infringement of your original copyright, please let us know and we will delete the relevant content as soon as possible.

Original: https://blog.csdn.net/weixin_30306285/article/details/112900224
Author: 蒸汽猫marterio
Title: python 入门到实践第十二章 游戏不响应_Python实战【用Python写游戏第十二节】屡败屡战…

原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/363389/

转载文章受原作者版权保护。转载请注明原作者出处!

(0)

大家都在看

最近整理资源【免费获取】:   👉 程序员最新必读书单  | 👏 互联网各方向面试题下载 | ✌️计算机核心资源汇总