473,407 Members | 2,312 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

Am I on the right path

ADE
Hi everyone:

I was just wondering if this code makes sense to anyone. And if I am
writing it correctly, the program seems to keep crashing. I was also
wondering if anyone had any pointers.

The program is supposed to randomly choose an ip address and try and make a
conection on port 80

Cheers to anyone who helps

# GENERATE AND TRY AND CONNECT TO RANDOM IP ADDRESS

import socket, struct, random
RAND = random.random()
PORT = 80
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

# These two functions aren't mine
def dottedQuadToNum(ip):
"convert decimal dotted quad string to long integer"
return struct.unpack('L',socket.inet_aton(ip))[0]

def numToDottedQuad(n):
"convert long int to dotted quad string"
return socket.inet_ntoa(struct.pack('L',n))
# I Think I understand them

HOST = dottedQuadToNum("24.207.19.240")
RAND = random.randrange(HOST)
HOST = numToDottedQuad(RAND)

try:
sock.connect((HOST, PORT))
print "connected to " + HOST + " on",
print PORT
sock.close()
except:
print "could not connect to " + HOST + " on",
print PORT
Cheers

Thank You

Andrew
Jul 18 '05 #1
0 1285

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Bo Wisén | last post by:
Hi, A project in VB6 recently worked without any problems but now it's complaining when I try to use 'Right$'. In immediate mode, when I'm typing 'print left$("123456",2)' I get the correct...
6
by: Dean Slindee | last post by:
I am looking for the "right" way to handle inserting and presenting null date values. Public Const c_NullDate As Date = #12:00:00 AM# If I set the value of a date variable in an SQL Server insert...
3
by: Brett | last post by:
I've compiled a DLL which is being called from a different project. The following code is from the DLL. When I run the WriteToFile sub the second time from the spawning project, I get the error...
0
by: Thom Little | last post by:
What a curious use of the word rename ... It is stated that string strA= Path.GetTempFileName(); creates a temporary file name in the temp directory and ... Path.ChangeExtension( strA, "xxx" );...
5
by: Tim Daneliuk | last post by:
Ah yes, moral philosophy and python all come together... Er, that is to day: Imagine you have this situation on a *nix filesystem: Symlink A: /foo -/usr/home Symlink B: /bar -/foo/username ...
26
by: Clamato | last post by:
Hi everyone, I'm having the hardest time with an issue that you would think to be easy to do! But, being an access noob, I can't seem to get it to work. Access 2000. What I have is a tab...
5
by: | last post by:
What are the equivalant to left, right, etc. in C#. How can I extract strings from a string without them? For instance, I have a string like so: ...
32
by: Bob Greschke | last post by:
I'm reading 3-byte numbers from a file and they are signed (+8 to -8million). This seems to work, but I'm not sure it's right. # Convert the 3-characters into a number. Value1, Value2, Value3 =...
16
by: Stef Mientki | last post by:
hello, How can I find the correct case of a filename ? Background in my program I use case sensitive filenames, just like Python requires. Now I've integrated pdb into the program, but pdb...
5
by: kulabhishek | last post by:
Hello, I have developed one application, and added it to right click pop-up menu of the folder. Whenever user right-clicks on folder and selects my application from pop-up menu, I want the path...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.