Python Forum
invalid keyword arguments error
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
invalid keyword arguments error
#3
thanks.
Now I am getting typeError in the output.

import optparse
import socket
from socket import *


def connScan(tgtHost, tgtPort):
    try:
        connSkt = socket(AF_INET, SOCK_STREAM)
        connSkt.connect((tgtHost, tgtPort))
        connSkt.send('ViolentPython\r\n')
        results = connSkt.recv(100)
        print('[+]%d/tcp open' % tgtPort)
        print('[+]' + str(results))
        connSkt.close()
    except:
        print('[-]$d/tcp closed' % tgtPort)


def portScan(tgtHost, tgtPorts):
    try:
        tgtIP = gethostbyname(tgtHost)
    except:
        print("[-] Cannot resolve '%s': Unknown host" % tgtHost)
        return
    try:
        tgtName = gethostbyaddr(tgtIP)
        print('\n[+] Scan Results for: ' + tgtName[0])
    except:
        print('\n[+] Scan results for: ' + tgtIP)
    setdefaulttimeout(1)
    for tgtPort in tgtPorts:
        print('Scanning port' + tgtPort)
        connScan(tgtHost, int(tgtPort))


def main():
    parser = optparse.OptionParser("usage%prog " +
                                   "-H <target hsot> -p <target port>")
    parser.add_option('-H', dest='tgtHost', type='string',
                      help='specify target host')
    parser.add_option('-p', dest='tgtPort', type='string',
                      help='specify target port[s] separated by comma')
    (options, args) = parser.parse_args()
    tgtHost = options.tgtHost
    tgtPorts = str(options.tgtPort).split(', ')
    if (tgtHost == None) | (tgtPorts[0] == None):
        print('[-] You must specify a target host and part[s].')
        exit(0)
    portScan(tgtHost, tgtPorts)


if __name__ == '__main__':
    main()
Output:
[+] Scan Results for: TEST-LAB Scanning port21 Traceback (most recent call last): File "port_scan.py", line 9, in connScan connSkt.connect((tgtHost, tgtPort)) socket.timeout: timed out During handling of the above exception, another exception occurred: Traceback (most recent call last): File "port_scan.py", line 53, in <module> main() File "port_scan.py", line 49, in main portScan(tgtHost, tgtPorts) File "port_scan.py", line 33, in portScan connScan(tgtHost, int(tgtPort)) File "port_scan.py", line 16, in connScan print('[-]$d/tcp closed' % tgtPort) TypeError: not all arguments converted during string formatting
Reply


Messages In This Thread
invalid keyword arguments error - by sagpal - Jun-03-2020, 08:58 PM
RE: port_scan - by Yoriz - Jun-03-2020, 09:16 PM
RE: invalid keyword arguments error - by sagpal - Jun-04-2020, 03:16 PM
RE: invalid keyword arguments error - by bowlofred - Jun-04-2020, 10:24 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Find a specific keyword after another keyword and change the output sgtmcc 5 881 Oct-05-2023, 07:41 PM
Last Post: deanhystad
  error: invalid command 'egg_info' TimTu 0 990 Jul-27-2023, 07:30 AM
Last Post: TimTu
  Why doesn't calling a parent constructor work with arbitrary keyword arguments? PurposefulCoder 4 985 Jun-24-2023, 02:14 PM
Last Post: deanhystad
  [ERROR] ParamValidationError: Parameter validation failed: Invalid type for parameter gdbengo 3 11,245 Dec-26-2022, 08:48 AM
Last Post: ibreeden
  Error TypeError: output_type_handler() takes 2 positional arguments but 6 were given paulo79 1 1,990 Oct-17-2022, 06:29 PM
Last Post: paulo79
  Invalid format specifier Error Led_Zeppelin 2 7,958 Jul-11-2022, 03:55 PM
Last Post: Led_Zeppelin
Exclamation Invalid syntax error(Predict Ethereum Price) lulu43366 2 3,205 Sep-24-2021, 01:24 PM
Last Post: lulu43366
  Unexplained Invalid syntax Error cybertooth 5 3,335 Aug-02-2021, 10:05 AM
Last Post: cybertooth
  Invalid syntax error - need help fixing calgk01 3 3,336 Feb-23-2021, 08:41 PM
Last Post: nilamo
  Error on nested loop : Invalid syntax dvazquezgu 3 3,284 Nov-25-2020, 10:04 AM
Last Post: palladium

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020