Giter Club home page Giter Club logo

networkscanner's Introduction

Hi there ๐Ÿ‘‹

networkscanner's People

Contributors

yura-choi avatar

Watchers

 avatar

networkscanner's Issues

Error: socket.sendto function: invalid argument


  • environment

    • mac OS
  • test code

import socket

src_ip = '127.0.0.1'
dest_ip = '127.0.0.1'
src_port = 8088
dest_port = 80

raw_socket = socket.socket(socket.AF_INET, socket.SOCK_RAW, socket.IPPROTO_TCP)
raw_socket.setsockopt(socket.IPPROTO_IP, socket.IP_HDRINCL, 1)

ip_header = b"\x45\x00\x00\x40" # version, ihl, tos, Total length
ip_header += b"\x00\x00\x40\x00" # id, IP flags, fragment offset
ip_header += b"\x40\x06\x00\x00" # TTL, protocol, header checksum
ip_header += socket.inet_aton(src_ip) # source address
ip_header += socket.inet_aton(dest_ip) # destination address

tcp_header = src_port.to_bytes(2, 'big') + dest_port.to_bytes(2, 'big') # source port, destination port
tcp_header += b"\x00\x00\x00\x00" # seq number
tcp_header += b"\x00\x00\x00\x00" # ack number
tcp_header += b"\x50\x02\xff\xff" # offset, reserved, TCP flags, window
tcp_header += b"\x00\x00\x00\x00" # checksum, urgent pointer

raw_socket.sendto(ip_header + tcp_header, (dest_ip, dest_port))

response, _ = raw_socket.recvfrom(4096)
if response:
    tcp_flag = int.from_bytes(response[33:34], "big")
    if tcp_flag == 18: # SYN/ACK
        print(f"{dest_port} is opened")
    elif tcp_flag == 20: # RST
        print(f"{dest_port} is closed")
  • result
    raw_socket.sendto(ip_header + tcp_header, (dest_ip, dest_port))
OSError: [Errno 22] Invalid argument

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.