当前位置: 首页>>代码示例>>Python>>正文


Python Wireless.getMode方法代码示例

本文整理汇总了Python中pythonwifi.iwlibs.Wireless.getMode方法的典型用法代码示例。如果您正苦于以下问题:Python Wireless.getMode方法的具体用法?Python Wireless.getMode怎么用?Python Wireless.getMode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pythonwifi.iwlibs.Wireless的用法示例。


在下文中一共展示了Wireless.getMode方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: TestWireless

# 需要导入模块: from pythonwifi.iwlibs import Wireless [as 别名]
# 或者: from pythonwifi.iwlibs.Wireless import getMode [as 别名]
class TestWireless(unittest.TestCase):

    def setUp(self):
        ifnames = getNICnames()
        self.wifi = Wireless(ifnames[0])

    def test_wirelessMethods(self):
        # test all wireless methods that they don't return an error
        methods = ['getAPaddr',
                   'getBitrate',
                   'getBitrates',
                   'getChannelInfo',
                   'getEssid',
                   'getFragmentation',
                   'getFrequency',
                   'getMode',
                   'getNwids',
                   'getWirelessName',
                   'getPowermanagement',
                   'getQualityMax',
                   'getQualityAvg',
                   'getRetrylimit',
                   'getRTS',
                   'getSensitivity',
                   'getTXPower',
                   'getStatistics',
                   'commit']

        for m in methods:
            result = getattr(self.wifi, m)()

        old_mode = self.wifi.getMode()
        self.wifi.setMode('Monitor')
        self.assert_(self.wifi.getMode() == 'Monitor')
        self.wifi.setMode(old_mode)

        old_essid = self.wifi.getEssid()
        self.wifi.setEssid('Joost')
        self.assert_(self.wifi.getEssid() == 'Joost')
        self.wifi.setEssid(old_essid)

        old_freq = self.wifi.getFrequency()
        self.wifi.setFrequency('2.462GHz')
        self.assert_(self.wifi.getFrequency() == '2.462GHz')
        self.wifi.setFrequency(old_freq)

        # test setAPaddr - does not work unless AP is real and available
        #old_mac = self.wifi.getAPaddr()
        #self.wifi.setAPaddr('61:62:63:64:65:66')
        #time.sleep(3)                                     # 3 second delay between set and get required
        #self.assert_(self.wifi.getAPaddr() == '61:62:63:64:65:66')
        #self.wifi.setAPaddr(old_mac)

        old_enc = self.wifi.getEncryption()
        self.wifi.setEncryption('restricted')
        self.assert_(self.wifi.getEncryption() == 'restricted')
        self.assert_(self.wifi.getEncryption(symbolic=False) \
                        == IW_ENCODE_RESTRICTED+1)
        self.wifi.setEncryption(old_enc)

        try:
            old_key = self.wifi.getKey()
        except ValueError, msg:
            old_key = None
        self.wifi.setKey('ABCDEF1234', 1)
        self.assert_(self.wifi.getKey() == 'ABCD-EF12-34')
        self.assert_(map(hex, self.wifi.getKey(formatted=False)) \
                        == ['0xab', '0xcd', '0xef', '0x12', '0x34'])
        if old_key:
            self.wifi.setKey(old_key, 1)
        else:
            self.wifi.setEncryption('off')
开发者ID:FomkaV,项目名称:wifi-arsenal,代码行数:74,代码来源:test_wireless.py

示例2: Wireless

# 需要导入模块: from pythonwifi.iwlibs import Wireless [as 别名]
# 或者: from pythonwifi.iwlibs.Wireless import getMode [as 别名]
from pythonwifi.iwlibs import Wireless
wifi = Wireless('wlan0')
print wifi.getEssid()
print wifi.getMode()

开发者ID:mstfmomin,项目名称:labmonembedded,代码行数:6,代码来源:wifitest1.py

示例3: main

# 需要导入模块: from pythonwifi.iwlibs import Wireless [as 别名]
# 或者: from pythonwifi.iwlibs.Wireless import getMode [as 别名]
def main():
    global ip_lst
    # status.noc.stonybrook.edu
    parser = argparse.ArgumentParser(description="man on the side attack detector.")
    parser.add_argument("-i", "--ifname", help="interface to use", type=str, required=False, default="wlp1s0")

    parser.add_argument("-o", "--out-file", help="file to write live ip's to", type=str, required=False, default=None)

    parser.add_argument(
        "-t",
        "--cache-clear-interv",
        help="how long to wait before clearing the ARP cache",
        type=int,
        required=False,
        default=0,
    )

    parser.add_argument(
        "-m", "--mu", help="how long to wait before pinging the next random IP", type=float, required=False, default=0
    )

    args = parser.parse_args()

    ifname = args.ifname

    mask = get_netmask(ifname)
    ip_str = get_ipaddress(ifname)

    print("mask: " + mask)
    print("ip: " + ip_str)

    ip = netaddr.IPNetwork(ip_str + "/" + mask)
    print(ip)

    found_ips = []

    # scan whole network for live computers
    ans, unans = arping(str(ip.network) + "/" + str(ip.prefixlen), iface=ifname)

    # record all of the live IP's
    for i in ans:
        found_ips.append(i[0][ARP].pdst)

    print("found " + str(len(found_ips)) + " IPs")

    # write the IP's to a file if requested
    if args.out_file is not None:
        outfile = open(args.out_file, "w")
        wifi = Wireless(ifname)
        outfile.write("args: " + str(args) + "\n")
        outfile.write("essid: " + wifi.getEssid() + "\n")
        outfile.write("mode: " + wifi.getMode() + "\n")
        outfile.write("mask: " + mask + "\n")
        outfile.write("ip: " + ip_str + "\n")
        outfile.write("network: " + str(ip.network) + "/" + str(ip.prefixlen) + "\n")

        outfile.write("\n".join(found_ips))
        outfile.write("\n")
        outfile.close()

    # schedule the ARP cache clearing
    if args.cache_clear_interv > 0:
        t = threading.Thread(target=clear_cache_timer, args=[args.cache_clear_interv])
        t.start()

    # schedule the pinging
    if args.mu <= 0:
        sys.exit(1)

    ip_lst = found_ips
    random.shuffle(ip_lst)

    # signal.signal(signal.SIGALRM, ping_rnd)
    # signal.setitimer(signal.ITIMER_REAL, args.mu, args.mu)

    while True:
        # signal.pause()
        t = threading.Thread(target=ping_rnd, args=["", ""])
        t.start()
        time.sleep(args.mu)
开发者ID:mjsalerno,项目名称:arptest,代码行数:82,代码来源:arptest.py

示例4: iwconfig

# 需要导入模块: from pythonwifi.iwlibs import Wireless [as 别名]
# 或者: from pythonwifi.iwlibs.Wireless import getMode [as 别名]
def iwconfig(interface):
    """ Get wireless information from the device driver. """
    if interface not in getWNICnames():
        print "%-8.16s  no wireless extensions." % (interface, )
    else:
        wifi = Wireless(interface)
        print """%-8.16s  %s  ESSID:"%s" """ % (interface,
            wifi.getWirelessName(), wifi.getEssid())
        if (wifi.wireless_info.getMode() == pythonwifi.flags.IW_MODE_ADHOC):
            ap_type = "Cell"
        else:
            ap_type = "Access Point"
        ap_addr = wifi.getAPaddr()
        if (ap_addr == "00:00:00:00:00:00"):
            ap_addr = "Not-Associated"
        print """          Mode:%s  Frequency:%s  %s: %s""" % (
            wifi.getMode(), wifi.getFrequency(), ap_type, ap_addr)

        # Bit Rate, TXPower, and Sensitivity line
        line = "          "
        bitrate = getBitrate(wifi)
        if bitrate:
            line = line + bitrate
        txpower = getTXPower(wifi)
        if txpower:
            line = line + txpower
        sensitivity = getSensitivity(wifi)
        if sensitivity:
            line = line + sensitivity
        print line

        # Retry, RTS, and Fragmentation line
        line = "          "
        retry = getRetrylimit(wifi)
        if retry:
            line = line + retry
        rts = getRTS(wifi)
        if rts:
            line = line + rts
        fragment = getFragmentation(wifi)
        if fragment:
            line = line + fragment
        print line

        # Encryption line
        line = "          "
        line = line + getEncryption(wifi)
        print line

        # Power Management line
        line = "          "
        line = line + getPowerManagement(wifi)
        print line

        stat, qual, discard, missed_beacon = wifi.getStatistics()

        # Link Quality, Signal Level and Noise Level line
        line = "          "
        line = line + "Link Quality:%s/100  " % (qual.quality, )
        line = line + "Signal level:%sdBm  " % (qual.signallevel, )
        line = line + "Noise level:%sdBm" % (qual.noiselevel, )
        print line

        # Rx line
        line = "          "
        line = line + "Rx invalid nwid:%s  " % (discard['nwid'], )
        line = line + "Rx invalid crypt:%s  " % (discard['code'], )
        line = line + "Rx invalid frag:%s" % (discard['fragment'], )
        print line

        # Tx line
        line = "          "
        line = line + "Tx excessive retries:%s  " % (discard['retries'], )
        line = line + "Invalid misc:%s   " % (discard['misc'], )
        line = line + "Missed beacon:%s" % (missed_beacon, )
        print line

    print
开发者ID:Thearith,项目名称:cg3002py,代码行数:80,代码来源:iwconfig.py

示例5: iwconfig

# 需要导入模块: from pythonwifi.iwlibs import Wireless [as 别名]
# 或者: from pythonwifi.iwlibs.Wireless import getMode [as 别名]
def iwconfig(interface):
    """ Get wireless information from the device driver. """
    if interface not in getWNICnames():
        print "%-8.16s  no wireless extensions." % (interface, )
    else:
        wifi = Wireless(interface)
        line = """%-8.16s  %s  """ % (interface, wifi.getWirelessName())
        if (wifi.getEssid()):
            line = line + """ESSID:"%s"  \n          """ % (wifi.getEssid(), )
        else:
            line = line + "ESSID:off/any  \n          "

        # Mode, Frequency, and Access Point
        line = line + "Mode:" + wifi.getMode()
        try:
            line = line + "  Frequency:" + wifi.getFrequency()
        except IOError, (error_number, error_string):
            # Some drivers do not return frequency info if not associated
            pass

        if (wifi.wireless_info.getMode() == pythonwifi.flags.IW_MODE_ADHOC):
            ap_type = "Cell"
        else:
            ap_type = "Access Point"
        ap_addr = wifi.getAPaddr()
        if (ap_addr == "00:00:00:00:00:00"):
            ap_addr = "Not-Associated"
        line = line + "  " + ap_type + ": " + ap_addr + "   "
        print line

        # Bit Rate, TXPower, and Sensitivity line
        line = "          "
        bitrate = getBitrate(wifi)
        if bitrate:
            line = line + bitrate
        txpower = getTXPower(wifi)
        if txpower:
            line = line + txpower
        sensitivity = getSensitivity(wifi)
        if sensitivity:
            line = line + sensitivity
        print line

        # Retry, RTS, and Fragmentation line
        line = "          "
        retry = getRetrylimit(wifi)
        if retry:
            line = line + retry
        rts = getRTS(wifi)
        if rts:
            line = line + rts
        fragment = getFragmentation(wifi)
        if fragment:
            line = line + fragment
        print line

        # Encryption line
        line = "          "
        line = line + getEncryption(wifi)
        print line

        # Power Management line
        line = "          "
        line = line + getPowerManagement(wifi)
        print line

        try:
            stat, qual, discard, missed_beacon = wifi.getStatistics()
        except IOError, (error_number, error_string):
            # Some drivers do not return statistics info if not associated
            pass
开发者ID:FomkaV,项目名称:wifi-arsenal,代码行数:73,代码来源:iwconfig.py

示例6: Wireless

# 需要导入模块: from pythonwifi.iwlibs import Wireless [as 别名]
# 或者: from pythonwifi.iwlibs.Wireless import getMode [as 别名]
# connect to network
from wifi import Cell, Scheme

# wifi information
wifi_ssid = "labpump123"
wifi_password = "labpump123"

# machine information
port = Cell.all('wlan0')[0]

print "Connecting..."

try:
    scheme = Scheme.for_cell('wlan0', wifi_ssid, port, wifi_password)
    scheme.save()

except:
    scheme = Scheme.find('wlan0', wifi_ssid)

finally:
    scheme.activate();

# check internet connection
from pythonwifi.iwlibs import Wireless

network = Wireless('wlan0')
print "Connected with "+network.getEssid()+"."
print ("" if network.getMode()=="Managed" else "Not ")+"Secured Connection."
开发者ID:mstfmomin,项目名称:labmonembedded,代码行数:30,代码来源:WifiTest2.py


注:本文中的pythonwifi.iwlibs.Wireless.getMode方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。