Jump to content

Simple Network Manipulation


Recommended Posts

Hello everyone! I am wanting to use AutoIt to make a simple program to manipulate my internet connection. However, I have not used AutoIt in some time and don't really know to start with this, nor do I know if it is even possible to do in this language.

Here are the parameters for my project.

  • Grab all current incoming IP addresses on a user button click
  • Deny all connections except those from the aforementioned IP addresses and some predefined IP ranges for a specified period of time

If anyone could give me some guidance on how to go about this, it would be very appreciated.

Coder's Helper >> Here[center][/center]

Link to comment
Share on other sites

Hello everyone! I am wanting to use AutoIt to make a simple program to manipulate my internet connection. However, I have not used AutoIt in some time and don't really know to start with this, nor do I know if it is even possible to do in this language.

Here are the parameters for my project.

  • Grab all current incoming IP addresses on a user button click
  • Deny all connections except those from the aforementioned IP addresses and some predefined IP ranges for a specified period of time

If anyone could give me some guidance on how to go about this, it would be very appreciated.

http://www.autoitscript.com/autoit3/docs/f...ons/TCPRecv.htm

Func SocketToIP($SHOCKET)
    Local $sockaddr, $aRet
   
    $sockaddr = DllStructCreate("short;ushort;uint;char[8]")

    $aRet = DllCall("Ws2_32.dll", "int", "getpeername", "int", $SHOCKET, _
            "ptr", DllStructGetPtr($sockaddr), "int*", DllStructGetSize($sockaddr))
    If Not @error And $aRet[0] = 0 Then
        $aRet = DllCall("Ws2_32.dll", "str", "inet_ntoa", "int", DllStructGetData($sockaddr, 3))
        If Not @error Then $aRet = $aRet[0]
    Else
        $aRet = 0
    EndIf

    $sockaddr = 0

    Return $aRet
EndFunc  ;==>SocketToIP

Then just do something along the lines if If NOT $ip Then etc.

I hope I understood you right.

Link to comment
Share on other sites

Yes, I looked into this function in the documentation already.

However, I am having trouble getting it to return anything besides 0.

Global $ip;Ip to listen on
Global $ip2;Ip you expect to connect
Global $port;port to listen on
Global $sock[2]
Global $sockip;Returned IP of the socket

TCPStartup()

$sock[0] = TCPListen($ip,$port)

Do
$sock[1] = TCPAccept($sock[0])
Until $sock[1] <> -1

While 1
$sockip = SockettoIP($sock[1])
If $sockip <> $ip2 Then
TCPCloseSocket($sock[1])
EndIf
Wend

Func SocketToIP($SHOCKET)
    Local $sockaddr, $aRet
  
    $sockaddr = DllStructCreate("short;ushort;uint;char[8]")

    $aRet = DllCall("Ws2_32.dll", "int", "getpeername", "int", $SHOCKET, _
            "ptr", DllStructGetPtr($sockaddr), "int*", DllStructGetSize($sockaddr))
    If Not @error And $aRet[0] = 0 Then
        $aRet = DllCall("Ws2_32.dll", "str", "inet_ntoa", "int", DllStructGetData($sockaddr, 3))
        If Not @error Then $aRet = $aRet[0]
    Else
        $aRet = 0
    EndIf

    $sockaddr = 0

    Return $aRet
EndFunc ;==>SocketToIP

This might work, I'm not at my computer so I cannot test.

Link to comment
Share on other sites

Global $ip;Ip to listen on
Global $ip2;Ip you expect to connect
Global $port;port to listen on
Global $sock[2]
Global $sockip;Returned IP of the socket

TCPStartup()

$sock[0] = TCPListen($ip,$port)

Do
$sock[1] = TCPAccept($sock[0])
Until $sock[1] <> -1

While 1
$sockip = SockettoIP($sock[1])
If $sockip <> $ip2 Then
TCPCloseSocket($sock[1])
EndIf
Wend

Func SocketToIP($SHOCKET)
    Local $sockaddr, $aRet
  
    $sockaddr = DllStructCreate("short;ushort;uint;char[8]")

    $aRet = DllCall("Ws2_32.dll", "int", "getpeername", "int", $SHOCKET, _
            "ptr", DllStructGetPtr($sockaddr), "int*", DllStructGetSize($sockaddr))
    If Not @error And $aRet[0] = 0 Then
        $aRet = DllCall("Ws2_32.dll", "str", "inet_ntoa", "int", DllStructGetData($sockaddr, 3))
        If Not @error Then $aRet = $aRet[0]
    Else
        $aRet = 0
    EndIf

    $sockaddr = 0

    Return $aRet
EndFunc;==>SocketToIP

This might work, I'm not at my computer so I cannot test.

I'm testing this now, however won't this only return 1 IP address? I am expecting to get multiple, and then store them so that I can check against them later.

I want to know all of the IP addresses currently connected (on port 3074), store all of those (probably 4 of them) and then deny all other incoming connections for 10 seconds (BESIDES those 4 IP addresses and 3 other IP ranges) and after that, allow all connections again. I'm sorry if this is confusing lol.

Coder's Helper >> Here[center][/center]

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...