我正在尝试在我的设置模块中调用方法hello,但它应与from shodan.shodan import myclass
一起正常工作,但似乎无法使用文件结构,也无法导入文件和调用。这是我正在做的练习的原型,但似乎不能与类一起使用并打印hello方法
.
├── core
│ ├── __init__.py
│ ├── __init__.pyc
│ ├── settings.py
│ └── settings.pyc
├── google
│ ├── google.py
│ ├── google.pyc
│ ├── __init__.py
│ ├── __init__.pyc
│ └── modules
│ ├── images.py
│ ├── __init__.py
│ ├── __init__.pyc
│ ├── utils.py
│ └── utils.pyc
├── loop.sh
├── main.py
├── names
├── shodan
│ ├── __init__.py
│ ├── __init__.pyc
│ ├── shodan.py
│ └── shodan.pyc
└── unix.sh
settings.py
from optparse import OptionParser
from sys import platform as _platform
from google.google import *
from shodan.shodan import *
def settings(argv=None):
if _platform == "linux" or _platform == "linux2":
#Linux
CrossPlatformCommandLineParser()
elif _platform == "darwin":
# MAC OS X
CrossPlatformCommandLineParser()
elif _platform == "win32":
# Windows
CrossPlatformCommandLineParser()
elif _platform == "win64":
# Windows 64-bit
CrossPlatformCommandLineParser()
def CrossPlatformCommandLineParser(argv=None):
if _platform == "linux" or _platform == "linux2":
#Linux
#print 'Linux ' + 'new cyber weapon'
#google()
shodan = Shodan()
shodan.hello()
elif _platform == "darwin":
# MAC OS X
print 2
elif _platform == "win32":
# Windows
print 3
elif _platform == "win64":
# Windows 64-bit
print 4
shodan.py
#!/usr/bin/python
class Shodan:
"""docstring for ClassName"""
def __init__(self, key):
self.key = "aaa"
def hello():
print '[+] shodan...' + self.key
main.py
#!/usr/bin/python
import sys
import core.settings
if __name__ == '__main__':
try:
core.settings.settings()
except KeyboardInterrupt:
print "interrupted by user.."
except:
sys.exit()
答案 0 :(得分:0)
您可以在settings.py中尝试这样的操作
导入整个shodan文件。然后尝试创建Shodan类的对象,并使用该对象调用hello方法。
这将导致您在settings.py文件中出现类似的情况。
from optparse import OptionParser
from sys import platform as _platform
from google.google import *
import shodan.shodan
def settings(argv=None):
if _platform == "linux" or _platform == "linux2":
#Linux
CrossPlatformCommandLineParser()
elif _platform == "darwin":
# MAC OS X
CrossPlatformCommandLineParser()
elif _platform == "win32":
# Windows
CrossPlatformCommandLineParser()
elif _platform == "win64":
# Windows 64-bit
CrossPlatformCommandLineParser()
def CrossPlatformCommandLineParser(argv=None):
if _platform == "linux" or _platform == "linux2":
#Linux
#print 'Linux ' + 'new cyber weapon'
#google()
shodanObject = shodan.Shodan("aaa")
shodanObject.hello()
elif _platform == "darwin":
# MAC OS X
print 2
elif _platform == "win32":
# Windows
print 3
elif _platform == "win64":
# Windows 64-bit
print 4
如下修改您的shodan:
class Shodan:
"""docstring for ClassName"""
key = ""
def __init__(self, key):
self.key = "aaa"
def hello():
print '[+] shodan...' + self.key
还要注意用于对象创建的settings.py中的更改。 shodanObject = shodan.Shodan(“ aaa”)此特定行。