Markdown 代码块能够突出显示特定语言的语法。通过在三重引号后指定样式,例如:
PowerShell
'''
我特意放了不同类型的引号,如何在 cmd 窗口中突出显示语法?如果您选择“批处理”文件类型,Visual Studio Code 会突出显示这一点,但我已经尝试了所有方法,但都不起作用(我在 Obsidian 中工作)
Markdown 代码块能够突出显示特定语言的语法。通过在三重引号后指定样式,例如:
PowerShell
'''
我特意放了不同类型的引号,如何在 cmd 窗口中突出显示语法?如果您选择“批处理”文件类型,Visual Studio Code 会突出显示这一点,但我已经尝试了所有方法,但都不起作用(我在 Obsidian 中工作)
请告诉我。有一个实用程序在某种情况下返回代码 70。我处理这种情况的代码不起作用,我做错了什么?
kesl-control --start-task 1 &> /dev/null
if [[ $? == 0 ]]; then
echo 1
elif [[ $? == 70 ]]; then
echo 2
else
echo 3
fi
理论上,如果返回码是 70,那么我的脚本应该输出2
,但在这种情况下它总是输出3
。我究竟做错了什么?
帮助我理解为什么会这样,这里是代码:
import re
TEXT = r'''
local afp = require "afp"
local nmap = require "nmap"
local shortport = require "shortport"
local stdnse = require "stdnse"
local string = require "string"
local table = require "table"
local unpwdb = require "unpwdb"
-- we don't really need openssl here, but let's attempt to load it as a way
-- to simply prevent the script from running, in case we don't have it
local openssl = stdnse.silent_require("openssl")
description = [[
Performs password guessing against Apple Filing Protocol (AFP).
]]
---
-- @usage
-- nmap -p 548 --script afp-brute <host>
--
-- @output
-- PORT STATE SERVICE
-- 548/tcp open afp
-- | afp-brute:
-- |_ admin:KenSentMe => Valid credentials
-- Information on AFP implementations
--
-- Snow Leopard
-- ------------
-- - Delay 10 seconds for accounts with more than 5 incorrect login attempts (good)
-- - Instant response if password is successful
--
-- Netatalk
-- --------
-- - Netatalk responds with a "Parameter error" when the username is invalid
--
author = "Patrik Karlsson"
license = "Same as Nmap--See https://nmap.org/book/man-legal.html"
categories = {"intrusive", "brute"}
-- Version 0.3
-- Created 01/15/2010 - v0.1 - created by Patrik Karlsson <patrik@cqure.net>
-- Revised 03/09/2010 - v0.2 - changed so that passwords are iterated over users
-- - this change makes better sense as guessing is slow
-- Revised 09/09/2011 - v0.3 - changed account status text to be more consistent with other *-brute scripts
portrule = shortport.port_or_service(548, "afp")
action = function( host, port )
local result, response, status = {}, nil, nil
local valid_accounts, found_users = {}, {}
local helper
local usernames, passwords
status, usernames = unpwdb.usernames()
if not status then return end
status, passwords = unpwdb.passwords()
if not status then return end
for password in passwords do
for username in usernames do
if ( not(found_users[username]) ) then
helper = afp.Helper:new()
status, response = helper:OpenSession( host, port )
if ( not(status) ) then
stdnse.debug1("OpenSession failed")
return
end
stdnse.debug1("Trying %s/%s ...", username, password)
status, response = helper:Login( username, password )
-- if the response is "Parameter error." we're dealing with Netatalk
-- This basically means that the user account does not exist
-- In this case, why bother continuing? Simply abort and thank Netatalk for the fish
if response:match("Parameter error.") then
stdnse.debug1("Netatalk told us the user does not exist! Thanks.")
-- mark it as "found" to skip it
found_users[username] = true
end
if status then
-- Add credentials for other afp scripts to use
if nmap.registry.afp == nil then
nmap.registry.afp = {}
end
nmap.registry.afp[username]=password
found_users[username] = true
table.insert( valid_accounts, string.format("%s:%s => Valid credentials", username, password:len()>0 and password or "<empty>" ) )
break
end
helper:CloseSession()
end
end
usernames("reset")
end
local output = stdnse.format_output(true, valid_accounts)
return output
end
'''
description_regex = re.compile(r'description = \[\[.*\]\]', flags=re.DOTALL)
categories_regex = re.compile(r'categories = \{.*\}', flags=re.DOTALL)
script_description = re.search(description_regex, TEXT)
print(script_description.group(0))
script_categories = re.search(categories_regex, TEXT)
print(script_categories.group(0))
为什么 script_categories 以模式后的所有文本结尾?但不是categories = {"intrusive", "brute"}
它的意图?
有一个代码:
import socket
s = socket.socket()
s.connect(('192.168.0.195', 6969))
with open('hello.txt', "rb") as f:
buffer = f.read(4096)
while buffer:
s.sendall(buffer)
buffer = f.read(4096)
s.close()
是否可以将它写在一行中(通过;),以便可以通过执行python -c '...'
?
该函数是否format()
将所有参数隐式转换为str
?
此代码引发错误:
a = 10
print('A: ' + a)
但是没有一个:
a = 10
print('A: {}'.format(a)
如果有一个隐式转换,那么它不是多余的吗?在最简单的情况下,当你可以不用format()
, 来连接时,它会不会更好+
?
有一个脚本,它的主要部分是:
try:
con = sqlite3.connect('Posts.db')
cur = con.cursor()
...
except:
...
except:
finally:
cur.close()
con.close()
事实是,在我的代码中,打开连接和游标后,会产生错误,无论是否发生错误,我都想关闭连接。
怎么安排最好?在每个例外中,我在错误 print 之后都有一个 raise SystemExit
。如果我最后写:
cur.close()
con.close()
那么事情可能达不到他们的执行?是的,解释器抛出错误。NameError: name 'cur' is not defined
我在哪里或如何在终端中看到它们?我只知道 sysctl、systemctl、hostnamectl、localectl 和 timedatectl,不知道是不是全部。
大家好。有一个主窗体,在它 DataGridView 中,我想用我创建的流程中的数字填充它。是否可以将多个语句中的 lambda 作为参数传递给方法(在本例中为构造函数)?我知道您可以在构造函数之前声明一个委托并传递一个包含对该对象的引用的变量。在我看来它看起来更漂亮,但这个选项是错误的。
private void SetData(object number)
{
DataTable.Invoke(new Action<int>(n =>
{
DataTable.RowCount = n;
for (int i = 0; i < n; i++)
{
DataTable.Rows[i].Cells[0].Value = i.ToString();
DataTable.Update();
}
};), (int)number);
}
private void StartButtonClick(object sender, EventArgs e)
{
Thread thread = new Thread(SetData);
thread.Start(10000);
}
我遇到了一个问题,在 WPF 项目中,使用 XAML 编辑器处理窗口的一半和使用设计器处理窗口的一半是不方便的。我将显示设置为全屏,但是现在,为了从设计器切换到编辑器并返回,您需要不断地单击鼠标。
您可以从编辑器切换到构造器Shift+ F7。
有谁知道反向操作的热键?Ctrl++Alt转换0为代码,但您需要将其转换为 XAML。