forked from linpeng109/py_metasploit_20200409
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpy_config.py
29 lines (22 loc) · 959 Bytes
/
py_config.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import configparser
from configparser import ConfigParser
class ConfigFactory(ConfigParser):
def __init__(self, config_file: str):
super(ConfigFactory, self).__init__()
self.config = config_file
# 在配置文件中使用变量调用
def optionxform(self, optionstr):
return optionstr
def setConfig(self, section, option, value):
self.read(self.config, 'gbk')
self.set(section=section, option=option, value=value)
with open(self.config, 'w') as config_file:
self.write(config_file)
def getConfig(self):
# 在配置文件中使用变量调用
self._interpolation = configparser.ExtendedInterpolation()
self.read(filenames=self.config, encoding='gbk')
return self
if __name__ == '__main__':
cfg = ConfigFactory(config_file='py_metasploit.ini').getConfig()
cfg.setConfig(section='surpac', option='surpac_location', value='c:/system5')