ChatGPTにスイッチのACL呪文 "port-bitmask" を唱えさせたい(失敗中)

※2023/8/9 無理してChatGPTでやらせないほうが良かったかも

最初からこういう解決策を探せばよかった。

ここのpythonコードで計算できた。

stackoverflow.com

 

・・・・・・・・・・・・・・・・・・・

とあるスイッチのACLTCP/UDPのポート範囲を指定する場合に用いられる port-bitmask を自分で考えるのが面倒なので、ChatGPTに計算させたい。

が、うまくいってない。

誰かこのプロンプトを修正して成功させてほしい・・・。

ちゃんとプロンプトの勉強しなきゃ・・・。

ひょっとしてそもそもプロンプトの中身が間違ってるのかな・・・。自信なくなってきた・・・。

ネットワークスイッチデバイスの拡張ACLにport-bitmaskを用いて、
複数のTCPポート、または、UDPポートを指定する方法があります。

宛先ポートを示す書式は以下のとおりです。
destination-port [port] [port-bitmask]

port-bitmaskを省略すると[port]1つのポートを指定したことになります。

destination-port 0 64512
について解説します。

[port]で指定された"0"は16桁の2進数にすると
0000 0000 0000 0000

[port-bitmask]で指定された"64512"は16桁の2進数にすると
1111 1100 0000 0000

2進数の[port-bitmask]によりマスクされた"1"以外の桁が自由であり、
[port]を基準とした場合の最小値
0000 0000 0000 0000 = 0

2進数の[port-bitmask]によりマスクされた"1"以外の桁が自由であり、
[port]を基準とした場合の最大値
0000 0011 1111 1111 = 1023

よって最小値〜最大値の値が指定されたことになり、
ポート0から1023までを指定したことになります。

Q1:ポート0から1023までを指定
A1:destination-port 0 64512 // 0-1023

Q2:ポート20000から20011を指定
A2:destination-port 20000 65528 // 20000-20007
   destination-port 20008 65532 // 20008-20011

Q3:ポート1024から2047を指定
A3:destination-port 1024 64512 // 1024-2047

Q4:ポート1024から65535を指定
A4:destination-port 1024 64512 // 1024-2047
   destination-port 2048 63488 // 2048-4095
   destination-port 4096 61440 // 4096-8191
   destination-port 8192 57344 // 8192-16383
   destination-port 16384 49152 // 16384-32767
   destination-port 32768 32768 // 32768-65535

Q5:ポート1024から64511を指定
A5:destination-port 1024 64512 // 1024-2047
   destination-port 2048 63488 // 2048-4095
   destination-port 4096 61440 // 4096-8191
   destination-port 8192 57344 // 8192-16383
   destination-port 16384 49152 // 16384-32767
   destination-port 32768 49152 // 32768-49151
   destination-port 49152 57344 // 59152-57343
   destination-port 57344 61440 // 57344-61439
   destination-port 61440 63488 // 61440-63487
   destination-port 63488 64512 // 63488-64511

Q6:ポート3500から4000を指定
A6:destination-port 3500 65532 // 3500-3503
   destination-port 3504 65520 // 3504-3519
   destination-port 3520 65472 // 3520-3583
   destination-port 3584 65024 // 3584-3839
   destination-port 3840 65280 // 3840-3967
   destination-port 3968 65504 // 3968-3999
   destination-port 4000 65535 // 4000

Q7:ポート30001から30200
A7:

A7の正解がほしいのに間違う。

正解は、

destination port 30001 65535 // 30001
destination port 30002 65534 // 30002-30003
destination port 30004 65532 // 30004-30007
destination port 30008 65528 // 30008-30015
destination port 30016 65472 // 30016-30079
destination port 30080 65472 // 30080-30143
destination port 30144 65504 // 30144-30175
destination port 30176 65520 // 30176-30191
destination port 30192 65528 // 30192-30199
destination port 30200 65535 // 30200

こうなるはず。

 

このプロンプトが成功したら、"deny"と"permit"を組み合わせて少ない行でポート指定する方法もやりたい。